Fix Common AppleScript Errors

Every AppleScript beginner hits the same handful of errors. Here’s what each one actually means and how to fix it — not just the workaround, but the reason it happens.

“Not authorized to send Apple events to [App]”

What it means: macOS requires explicit permission before one app (like Script Editor) can control another (like Mail or Finder). This is a privacy protection, not a bug.

Fix:

  1. Go to System Settings → Privacy & Security → Automation
  2. Find Script Editor (or whatever app is running your script)
  3. Enable the checkbox next to the app your script is trying to control

If you exported your script as a standalone app, look for that app’s name in the Automation list instead.

“Can’t get file [X] of folder [Y]”

What it means: The script is trying to reference a file or folder that doesn’t exist — either it was moved, renamed, or the path/name in your script has a typo.

Fix: Double-check spelling and capitalization exactly. AppleScript is picky about exact names. Consider wrapping risky operations in a check:

tell application "Finder"
    if exists file "report.pdf" of desktop then
        -- safe to proceed
    else
        display dialog "File not found."
    end if
end tell

Syntax Error: “Expected end of line, etc. but found…”

What it means: This is AppleScript’s version of a typo error — a missing end tell, a stray character, or mismatched quotes.

Fix: Check that every tell, if, and repeat has its matching end tell, end if, or end repeat. Script Editor’s syntax highlighting helps — unmatched blocks often show up in a different color or with obvious indentation breaks.

Common culprit — smart quotes. If you copy code from a website or Word doc, curly quotes (" ") can sneak in instead of straight quotes ("), and AppleScript won’t recognize them:

-- Broken (smart quotes):
display dialog Hello

-- Fixed (straight quotes):
display dialog "Hello"

“Application isn’t running” / “Connection is invalid”

What it means: Your script is trying to control an app that isn’t currently open.

Fix: Add activate before your commands, or check is running first:

tell application "Mail"
    if not running then
        activate
        delay 2 -- give it a moment to launch
    end if
    -- your commands here
end tell

“Can’t set [property] of [object]”

What it means: You’re trying to change something that’s either read-only, or the object reference is wrong.

Fix: Common cause is naming collisions — trying to rename a file to a name that already exists in that folder:

tell application "Finder"
    if not (exists file "newname.txt" of targetFolder) then
        set name of theFile to "newname.txt"
    else
        display dialog "A file with that name already exists."
    end if
end tell

Script Runs But Nothing Happens

What it means: Usually your filtering condition (an if, or a whose clause) didn’t match anything — not an error, just zero results.

Fix: Add a quick debug line to check what’s actually being found:

set matchingItems to (every file of targetFolder whose name contains "invoice")
display dialog "Found: " & (count of matchingItems)

If the count is 0, your search text or condition needs adjusting.

“Timeout” or Script Hangs Forever

What it means: The app you’re controlling is waiting on something — often a dialog box hidden behind another window, or a slow operation (like a large do shell script command).

Fix: Add an explicit timeout around the risky section:

with timeout of 30 seconds
    tell application "Mail"
        -- slow operation here
    end tell
end timeout

Still Stuck?

Post the exact error message on r/applescript — the community is fast and genuinely helpful with beginner questions.

Or skip the debugging entirely: Scriptly generates tested, working AppleScript from a plain-English description, so you’re starting from working code instead of fixing broken code.