The detached thread had no run loop, so AESendMessage(kAEWaitReply) for the long
~25s notes fetch never received its reply (errored). Marshal scripts onto one
long-lived thread that owns a continuously-running CFRunLoop: in-process (TCC
attributes the event to MacSync, grant honored), real run loop (reply pumped),
off-main (no agent freeze). Also log the AppleScript error with .public privacy
so failures are visible instead of os_log's <private> redaction.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Surface the underlying NSAppleScript errorMessage instead of a bare
"script failed", to diagnose the Notes read failure mode.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
A ~25s `tell application "Notes"` read on the main actor blocks the run loop the
app and sync coordinator need (the read silently stalled — no fetch, no error).
Run it on a fresh thread via a continuation: NSAppleScript.executeAndReturnError
is synchronous and handles its own Apple-event reply, so it keeps the in-process
TCC attribution (the grant applies) without blocking the main thread.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
osascript runs out-of-process, so TCC attributes the Apple event to osascript
rather than MacSync — every Notes read was denied even after the user granted
MacSync → Notes Automation (the script works fine from Terminal). Send the
event in-process via NSAppleScript on the main actor (tell-application events
need a live run loop for their reply); the grant is then honored and notes
sync. The read is infrequent (600s cycle) and brief enough for a menu agent.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
`tell application "Notes" to get name` resolves the app's bundle name WITHOUT
sending an Apple event, so it never triggers the TCC Automation prompt — Notes
stayed ungranted and unsynced while Messages (granted via a real data event)
worked. Probe with `count notes`, a real automation event, in both the inotes
authorization cycle (auto, no menu click) and the tray "Grant Automation" item
(now data-reading per app: chats/accounts/notes).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>