You ran an Apple Notes automation and got this:
[read-note] Error: 435:470: syntax error: Error on line 14: SyntaxError: Return statements are only valid inside functions. (-2700)
Or your tool can read Notes but cannot write, even though Notes is switched on under Privacy & Security > Automation. These are two separate failures with different causes, so the fixes are not interchangeable.
Which problem do you have?
| What you see | Likely cause | Fix |
|---|---|---|
SyntaxError: Return statements are only valid inside functions. (-2700) |
JXA script with a top-level return |
Fix 1 |
| Reads work, writes fail, Notes toggle is on | Permission is tied to a different process than the one you approved | Fixes 2 to 4 |
Not authorized to send Apple events to Notes. (-1743) |
Automation permission denied or never granted | Fixes 3 and 4 |
The -2700 error is a problem in the script text. A permission problem normally produces -1743 instead.
Why it happens
The syntax error. The wording "valid inside functions" is a JavaScript message, not an AppleScript one. So the text was most likely compiled as JXA (osascript -l JavaScript). In AppleScript a top-level return is fine, but JXA rejects it. The 435:470 and "line 14" most likely point into a script the tool built, not something you typed. The error was reported against an Apple Notes MCP server's read_note call on November 6, 2026, and no resolution had been posted in that report.
The blocked write. macOS grants Automation permission to one specific app for one specific target app. In an OpenClaw bug report, the Node process started from Terminal and the Node process started by OpenClaw appeared to macOS as separate contexts. Approving one did not approve the other. The maintainers closed that report as not planned on February 28, 2026, so that tool has no fix to wait for. The reporter noted that osascript from Terminal worked.
We don't know why the toggle looks on while writes still fail. The separate-process explanation fits the report, but Apple has not confirmed it.
Fix 1: Wrap the JXA script in a run function
In a JXA script, osascript calls a function named run as the entry point, and return belongs inside it. Apple's Mac Automation Scripting Guide section on handlers and functions covers how handlers and functions work in scripts.
If you control the script, change this:
const Notes = Application("Notes");
return Notes.notes[0].name();
to this:
function run() {
const Notes = Application("Notes");
return Notes.notes[0].name();
}
If a tool generates the script, you can't fix it from your side. Update the tool, then report the bug (see "If nothing works"). Meanwhile, run your own script from Terminal as in Fix 2.
Fix 2: Test the same operation from Terminal
Running the operation outside the tool shows whether the problem is Notes, your permissions or the tool.
Count your notes with AppleScript:
osascript -e 'tell application "Notes" to count notes'
Read the first note's name with JXA, the same language as the failing script (this errors if you have no notes):
osascript -l JavaScript -e 'Application("Notes").notes[0].name()'
Test a write. This creates a real note, so delete it afterward:
osascript -e 'tell application "Notes" to make new note with properties {body:"Test from osascript"}'
The first run may show a macOS prompt asking whether Terminal may control Notes. Click OK. Apart from the test note, these commands change nothing.
If all three work, Notes itself is fine. The fault is in the tool or in how macOS attributes its permission, which is what the OpenClaw reporter saw.
Fix 3: Check Automation for the app that runs the script
Approve the app that actually launches the script (the agent or tool), not only Terminal.
- Open System Settings and go to Privacy & Security. You may need to scroll the sidebar.
- Click Automation.
- Find the tool in the list and expand it.
- Make sure Notes is switched on under it.
- If the tool is missing from the list, it has never triggered the prompt. Go to Fix 4.
- Quit and reopen the tool, then retry the write.
Apple's help page, Allow apps to control other apps on Mac, describes this list and the per-app switches.
If the tool is a wrapper (a Node process, a Python runner, an app that spawns a shell), the process that sends the Apple event may not match the app name you see in the list. Try launching the tool from a different parent, such as Terminal instead of a launcher, and see whether the behavior changes.
Fix 4: Reset Automation permissions and approve again
If you clicked Don't Allow once, macOS does not ask again. A reset brings the prompt back.
tccutil reset AppleEvents
To limit the reset to one app, add its bundle ID at the end, for example:
tccutil reset AppleEvents com.apple.Terminal
Then quit the tool and relaunch it, trigger a Notes write and approve the prompt. You can't undo the reset, but you restore access by approving the prompts as they appear.
What each cause looks like
| Cause | Symptom | Fix |
|---|---|---|
Top-level return in JXA |
-2700 syntax error, same line numbers every time |
Fix 1 |
| Tool is a different process than the one approved | Reads work, writes fail, toggle on | Fixes 3 and 4 |
| Prompt dismissed or denied once | -1743, no prompt appears |
Fix 4 |
| Bug in the tool's script generation | Works by hand in Terminal, fails in the tool | Update the tool or report it |
Checklist before you try again
- The script is either AppleScript, or JXA with a
function run() { ... }wrapper. - The three
osascripttests in Fix 2 work from Terminal. - Notes is on under the launching app in Privacy & Security > Automation.
- You quit and reopened the tool after changing permissions.
- On a work Mac, no management policy blocks Automation (ask your admin if unsure).
If nothing works
For the -2700 error, open or comment on an issue with the tool's maintainers. For the blocked write, say which app launches the process. Apple Support is only likely to help if a plain osascript call from Terminal also fails after Fix 4. Include:
- The full error line.
- Your macOS version and the tool's version.
- Results of the three Terminal tests.
- Whether Notes is on under Automation for the launching app.
Hi, your tool fails when it reads or writes Apple Notes.
Error: [read-note] Error: 435:470: syntax error: Error on line 14: SyntaxError: Return statements are only valid inside functions. (-2700)
macOS version: (your version)
Tool version: (your version)
It looks like a JXA script with a top-level return. Wrapping the body in function run() { ... } should avoid it.
Terminal checks: osascript count notes works / read name works / make new note works (edit to match).
Automation: Notes is on under (your tool's name) in Privacy & Security > Automation.
I already tried: tccutil reset AppleEvents, relaunching the tool.
Common questions
Is this a bug in Apple Notes?
Probably not. The -2700 message comes from a script compiled as JXA with a top-level return. If the equivalent commands work from Terminal, Notes is responding normally.
Why does Terminal work but my tool doesn't?
Automation permission is granted per app, so approving Terminal does not approve the tool's own process. In the OpenClaw report this was the pattern: Terminal worked, the tool could not write.
Is it safe to run tccutil reset AppleEvents?
It resets Automation approvals for all apps, so each one will prompt again. Check man tccutil for the exact behavior on your macOS version before running it on a managed Mac.
Can I avoid JXA entirely?
Yes. AppleScript can read and write Notes without a run wrapper, and a top-level return is valid there.
