Linking macOS notes with Omnifocus , any solutions since macOS Sonoma?

Hello!

I was wondering if someone have found any way to get the link that can be generated (since Sonoma) in the macOS’s Note app between notes. It would be very handful to put those links into the Omnifocus note’s field of a project. Unfortunately, when we copy the link generated in macOS, it doesn’t give any URL-scheme link…
That is something I was doing with the @temochka 's script but since few macOS versions it seems broken.

Thanks for helping!

2 Likes

Yes get the Hookmark app. I often link notes to various other apps.

1 Like

?? I just copied an inter-note link into Omnifocus and it seems to work just fine.

I haven’t upgraded to Sonoma yet, but the script hasn’t required any updates since Big Sur. It appears to work for me on Ventura. Urls now resolve through Shortcuts though (you can find links to my shortcuts here). The stub app is no longer needed. Just in case, the most recent version of the script is available on GitHub:

It compiles to this:

use framework "Foundation"
use scripting additions

property NSDate : a reference to current application's NSDate
property NSNumber : a reference to current application's NSNumber
property NSPasteboard : a reference to current application's NSPasteboard
property NSPasteboardTypeHTML : a reference to current application's NSPasteboardTypeHTML
property NSPasteboardTypeString : a reference to current application's NSPasteboardTypeString
property NSString : a reference to current application's NSString
property NSUTF16StringEncoding : a reference to current application's NSUTF16StringEncoding
property NOTE_SHORTCUTS_URL_PREFIX : "shortcuts://run-shortcut?name=NoteURL&input="
property NOTE_HOOK_URL_PREFIX : "hook://notes/dt/"

on clipTextAndHtml(theText, theHtml)
	set htmlBody to theHtml
	set nsStringHtmlBody to NSString's stringWithString:(htmlBody & "‌")
	set htmlBodyData to nsStringHtmlBody's dataUsingEncoding:NSUTF16StringEncoding
	set pb to NSPasteboard's generalPasteboard()
	pb's clearContents()
	pb's setString:theText forType:NSPasteboardTypeString
	pb's setData:htmlBodyData forType:NSPasteboardTypeHTML
end clipTextAndHtml

on getSelectedNoteIds()
	tell application "Notes"
		set ids to {}
		repeat with theNote in (selection as list)
			set ids to ids & {«class seld» of (theNote as record)}
		end repeat
		return ids
	end tell
end getSelectedNoteIds

on getNoteUri(noteId)
	tell application "Notes"
		set noteCreated to (creation date) of note id noteId in default account
		set cocoaDate to NSDate's dateWithTimeInterval:0 sinceDate:noteCreated
		set doubleNoteTimestamp to cocoaDate's timeIntervalSince1970
		set intNoteTimestamp to intValue of (NSNumber's numberWithDouble:doubleNoteTimestamp)
		set stringNoteTimestamp to stringValue of (NSNumber's numberWithInt:intNoteTimestamp)
		set shortcutsUri to (my NOTE_SHORTCUTS_URL_PREFIX) & stringNoteTimestamp
		set hookUri to (my NOTE_HOOK_URL_PREFIX) & stringNoteTimestamp
		return {shortcutsScheme:shortcutsUri, hookScheme:hookUri}
	end tell
end getNoteUri

tell application "Notes"
	set noteId to item 1 of (my getSelectedNoteIds())
	set uriRow to (my getNoteUri(noteId))'s shortcutsScheme
	set noteName to name of note id noteId in default account
	if noteName is not equal to "" then
		set titleRow to "“" & noteName & "”"
	else
		set titleRow to ""
	end if
	set textLink to titleRow & "

" & uriRow
	set htmlLink to titleRow & "<br>" & "<a href=\"" & uriRow & "\">" & uriRow & "</a>"
	
	my clipTextAndHtml(textLink, htmlLink)
end tell

That all said, I may not continue to update this script going forward as I completed my Notes->Obsidian migration earlier this year. Others have mentioned Hookmark above. It’s a good option that builds on my original script. There’s also this Alfred workflow that works really well: GitHub - sballin/alfred-search-notes-app: Use Alfred to quickly open notes in iCloud/Apple Notes.

Hope you can find something that works for you!

1 Like

Are you sure about that?? I can’t do it here. Could you explain how you do that, and if it was on idevice or Mac?

Thanks!

1 Like

Here was my error message
**error** "«script» ne comprend pas le message « getSelectedNoteIds »." number -1708 from «**script**»
In French > it means it don’t understand « getSelectedNoteIds »

I didn’t really understood what you meant about here

But when I copy this to the apple script editor, it’s now working fine!! I’m sorry to ask if it’s a beginner question, but I wonder how I could have it worked just by downloading the GitHub thing??

Thank you really much!
I’ll have a look again at Hookmark, I don’t remember why I finally never tried it!

it’s really not your fault: it’s organized in a way that’s most convenient for me. I never had the goal of making that repository usable by other people. Answering your question, you’d need to make a local copy of the Git repository and then run make in the root to compile the scripts. However, it’ll only compile successfully if you have all of the necessary software installed (AppleScript JSON Helper, Hookmark, OmniFocus, etc.).

1 Like