Interact with the Notes app on macOS
See 4d-utility-sign-app on how to enable the plugin in 4D.
Bug: It is no longer possible to add an attachment in macOS Catalina.
see:
https://hookproductivity.com/help2/integration/hook-and-macos-10-15-catalina-notes-app/ https://forum.latenightsw.com/t/notes-app-scripting-dictionary-defective-on-catalina/2136
tell application "Notes"
note id "x-coredata://2BB27C30-9D8D-4501-8ADD-D16531CA22F5/ICNote/p51"
(*
returns:
show id "x-coredata://2BB27C30-9D8D-4501-8ADD-D16531CA22F5/ICNote/p51" of application "Notes"
it is not possible to use this as a specifier; bummer! (error 1700)
*)
end tell
This version uses AEDeterminePermissionToAutomateTarget
from the 10.14 SDK
c.f. https://www.felix-schwarz.org/blog/2018/08/new-apple-event-apis-in-macos-mojave
This tool may help sign your application
If access has been previously denied by user, the application will not ask again.
The use must manually enable it.
Alternatively, you can clear all permissions for Automation.
tccutil reset AppleEvents
before
after
The main application must have the following keys in Info.plist
Key: Privacy - AppleEvents Sending Usage Description (NSAppleEventsUsageDescription
)
Value: Reason to access private data
If the entry does not exist, plugin calls will silently fail.
If the app is signed, you obviously have to sign it again after editing Info.plist
.
If the key exists, the system will ask the user for permission on the first attempt.
You will also need to codesign the built app (with the --deep
option, since some frameworks are unsigned).
To sign, you may have to xattr -rc
and first clean all files inside the app.
This plugin uses several different ways to access Notes.
The file Notes.h
was generated by sdef
.
sdef /Applications/Notes.app | sdp -fh --basename Notes
Most functions ask the Notes app to complete the task by sending obj-c
messaged over ScriptingBridge.
Adding attachments seems impossible via ScriptingBridge. So NSAppleScript is used instead.
The path of attachment files is likewise not exposed via AppleScript. So direct access to the backend SQLite database is performed.
- Example of connecting to the Notes backend SQLite database.
sqlite3 /Users/miyako/Library/Group\ Containers/group.com.apple.notes/NoteStore.sqlite