Tested on macOS Ventura.
I just built a script that uses the built-in Apple Notes URL scheme, so I can replace the default script for getting Apple Notes URLs.
Here’s how the script works:
- It gets the selected note’s ID and title.
- It splits up the ID at each
/
character which is a Core Data URL that looks like this: “x-coredata://A3B24705-E414-46EB-AF67-6E70FCCA3CE3/ICNote/p2405
”. - We have the last part,
p2405
in this case. The script removes thep
from the string, so we got the internal database ID of the selected note. - We can run a quick SQLite query to get the real identifier from the internal database of Notes at
~/Library/Group Containers/group.com.apple.notes/NoteStore.sqlite
.- It is stored in the
ZICCLOUDSYNCINGOBJECT
as theZIDENTIFIER
column. - Hook needs to have full disk access to make this work.
- It is stored in the
- Having the identifier from the database, we can return the final URL scheme in the form of
notes://showNote?identifier=EAE6848C-3556-407B-9CA0-A9C9E7CC26BD
.
This URL sadly works only on macOS. iOS uses the mobilenotes
protocol, so the same URL would be mobilenotes://showNote?identifier=EAE6848C-3556-407B-9CA0-A9C9E7CC26BD
.
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
tell application "Notes"
set theNoteID to «class seld» of (selection as record)
set theNoteName to name of note id theNoteID
end tell
set oldDelimiters to text item delimiters
set text item delimiters to "/"
set theTextItems to text items of theNoteID
set text item delimiters to oldDelimiters
set theIDPart to last item of theTextItems
set theIDPartCharacters to characters of theIDPart
set theIDPartCharacters to items 2 through -1 of theIDPartCharacters
set {oldDelimiters, text item delimiters} to {text item delimiters, ""}
set theNoteID to theIDPartCharacters as text
set text item delimiters to oldDelimiters
set theNoteIdentifier to do shell script "/usr/bin/sqlite3 ~/Library/Group\\ Containers/group.com.apple.notes/NoteStore.sqlite \"SELECT ZIDENTIFIER from ZICCLOUDSYNCINGOBJECT WHERE Z_PK = '" & theNoteID & "'\""
set theNoteURL to "notes://showNote?identifier=" & theNoteIdentifier
return "[" & theNoteName & "](" & theNoteURL & ")"
To replace the built-in script, just open Hook settings, go to Scripts, find Notes on the left and replace the Get Address script.
I found the inner workings of the Apple Notes URL scheme here.