Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/miyako/4d-plugin-notes

Interact with the Notes app on macOS
https://github.com/miyako/4d-plugin-notes

4d-plugin 4d-plugin-apple-silicon

Last synced: about 1 month ago
JSON representation

Interact with the Notes app on macOS

Awesome Lists containing this project

README

        

![version](https://img.shields.io/badge/version-19%2B-5682DF)
![platform](https://img.shields.io/static/v1?label=platform&message=mac-intel%20|%20mac-arm&color=blue)
[![license](https://img.shields.io/github/license/miyako/4d-plugin-notes)](LICENSE)
![downloads](https://img.shields.io/github/downloads/miyako/4d-plugin-notes/total)

# 4d-plugin-notes

Interact with the Notes app on macOS

See [4d-utility-sign-app](https://github.com/miyako/4d-utility-sign-app) on how to enable the plugin in 4D.

[Documentation](documentation.md)

**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

```applescript
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
```

## Important

This version uses [``AEDeterminePermissionToAutomateTarget``](https://developer.apple.com/documentation/coreservices/3025784-aedeterminepermissiontoautomatet?language=objc) 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](https://github.com/miyako/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](https://developer.apple.com/documentation/scriptingbridge).

### NSAppleScript

Adding attachments seems impossible via ScriptingBridge. So [NSAppleScript](https://developer.apple.com/documentation/foundation/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
```