Skip to content

miyako/4d-plugin-notes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 

Repository files navigation

4d-plugin-notes

Interact with the Notes app on macOS

Platform

carbon cocoa win32 win64

Version

before-mojave branch uses 10.13 SDK

Releases

3.0

Important

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

4d-utility-build-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

2019-03-05 16 01 49

after

2019-03-05 16 02 40

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.

2019-03-05 16 06 08

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.

2019-03-05 16 09 11

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.

Architecture

This plugin uses several different ways to access Notes.

ScriptingBridge

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.

NSAppleScript

Adding attachments seems impossible via ScriptingBridge. So NSAppleScript is used instead.

SQLite

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

Syntax

note:=Notes Create note (folder;title;body;attachments)
Parameter Type Description
folder TEXT
title TEXT
body TEXT
attachments ARRAY PICTURE
note TEXT JSON object

Properties of note:

  • id:string
  • name:string
  • body:string
  • creationDate:string
  • creationLocalDate:string
  • modificationDate:string
  • modificationLocalDate:string
Notes GET FOLDERS (folders)
Parameter Type Description
folders ARRAY TEXT names + JSON object in element 0

Properties of folders:

  • folders:array of folder

Properties of folder:

  • id:string
  • name:string
  • notes:array of string (id)
  • folders:array of folder (non-recursive)
Notes GET NOTES (notes)
Parameter Type Description
notes ARRAY TEXT names + JSON object in element 0

Properties of notes:

  • notes:array of note

Properties of note:

  • id:string
  • name:string
  • attachments:array of string (id)
Notes GET ATTACHMENTS (attachments)
Parameter Type Description
attachments ARRAY TEXT names + JSON object in element 0

Properties of attachments:

  • attachments:array of attachment

Properties of attachment:

  • id:string
  • name:string
  • note:string (id)
Notes GET ACCOUNTS (accounts)
Parameter Type Description
accounts ARRAY TEXT names + JSON object in element 0

Properties of accounts:

  • accounts:array of account

Properties of account:

  • id:string
  • name:string
  • folders:array of folder (non-recursive)
folder:=Notes Create folder (parent;name)
Parameter Type Description
parent TEXT
name TEXT
folder TEXT JSON object

Properties of folder:

  • id:string
  • name:string
path:=Notes Get attachment (id)
Parameter Type Description
attachment TEXT
path TEXT

Note: This methods call sqlite3 to resolve the attachment path.

note:=Notes Get note (id)
Parameter Type Description
id TEXT
note TEXT JSON object

Properties of note:

  • id:string
  • name:string
  • body:string
  • folder:string (id)
  • creationDate:string
  • creationLocalDate:string
  • modificationDate:string
  • modificationLocalDate:string
  • attachments:array of string (id)
folder:=Notes Get folder (id)
Parameter Type Description
id TEXT
folder TEXT JSON object

Properties of folder:

  • id:string
  • name:string
  • folders:array of folder(recursive)
  • notes:array of note (top level only)

Properties of note:

  • id:string
  • name:string
account:=Notes Get account (id)
Parameter Type Description
id TEXT
account TEXT

Properties of account:

  • id:string
  • name:string
  • folders:array of folder(recursive)

Notes SET NOTIFICATION (method)
Parameter Type Description
method TEXT
method:=Notes Get notification
Parameter Type Description
method TEXT

Remarks

The following methods are not implemented (does nothing) in this version

  • Notes SET NOTIFICATION (method)
  • method:=Notes Get notification