Hi everyone.
I’m trying to build a shortcut / automation to generate a deep link to an Apple Note so that I can add it in the URL field in Reminders. I have all of the building blocks built (thanks in large part to this post: NotesURLScheme). My issue is that whenever I run the following apple script in Automator or Shortcuts, I get an authorization error: “Error: unable to open database "/Users/USERNAME/Library/Group Containers/group.com.apple.notes/NoteStore.sqlite": authorization denied”.
Unless I run the sqlite query directly in Terminal, it fails. It fails with this error in the following circumstances:
Running the AppleScript from Shortcuts
Running the sqlite query from Shortcuts (with Run as Administer both off and on)
Running in Automator
Running as an Automator Application
I’ve tried changing the unix permissions all the way to rwx for all. I’ve tried adding Automator and Shortcuts to “Full Disk Access” - neither work. Interestingly, ig I add Script Editor to Full Disk Access, the script runs successfully.
Any pointers would be hugely welcome. Thanks all!
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 “” & theNoteURL & “”