AppleScript is the English-like scripting language built into macOS that automates applications and system tasks by sending them Apple events, the interprocess messages that scriptable apps understand. Within Terminal & scripting, it is the classic tool for controlling graphical apps such as Finder, Mail, Numbers or Photoshop, which shell commands alone cannot drive.
Introduced with System 7.1.1 in 1993, AppleScript still ships with every Mac. Scripts are written in Script Editor, run from the command line with osascript, or embedded in Shortcuts, Automator workflows, Folder Actions and third-party launchers.
How AppleScript sends Apple events
AppleScript works as a translator between readable commands and Apple events. A statement such as tell application "Finder" to get name of every window is compiled into a series of events addressed to the Finder process. The target app executes the request and returns a result, which the script can store in a variable or pass on.
Each scriptable app publishes a scripting dictionary, technically an sdef file, that lists its classes, properties and commands. Script Editor shows this dictionary through File > Open Dictionary, and it is the primary reference for what a given app can do. Apps without a dictionary can be controlled only indirectly, through GUI scripting of menus and buttons via System Events.
The language is built on the Open Scripting Architecture (OSA), which allows other languages to use the same event machinery. The most important sibling is JavaScript for Automation, introduced in OS X Yosemite, which reaches the same dictionaries with JavaScript syntax.
The following table summarizes the building blocks a script relies on.
| Element | Purpose | Example |
|---|---|---|
| tell block | Directs commands to one app | tell application “Mail” |
| Object specifier | Identifies an element inside an app | first message of inbox |
| Handler | Defines a reusable routine | on run, on open, custom handlers |
| Record and list | Hold structured data | {name:”A”, size:2} |
| try block | Catches runtime errors | try … on error … end try |
| do shell script | Runs a shell command and returns output | do shell script “date” |
Ways to run AppleScript on macOS
AppleScript can be run from several entry points, and the choice affects permissions, performance and how users trigger the automation. Compiled scripts are stored in the .scpt format, while plain-text source uses .applescript.
| Method | File or command | Best suited for |
|---|---|---|
| Script Editor | .scpt or .applescript | Writing, testing and reading dictionaries |
| osascript | osascript -e or a script path | Calling scripts from zsh, cron or launchd |
| Script applet | .app saved from Script Editor | Double-click tools and drag-and-drop droplets |
| Shortcuts action | Run AppleScript action | Mixing scripts with modern Shortcuts steps |
| Folder Actions | Script attached to a folder | Reacting to files added to a folder |
| Script menu | ~/Library/Scripts | Quick access from the menu bar |
From the shell, osascript is the bridge between Terminal and the GUI. It allows a zsh script, a Launch agent or a CI job to open documents, show dialogs or query app state, while do shell script works in the opposite direction and lets AppleScript call command-line tools such as mdfind or diskutil.
AppleScript compared with other macOS automation tools
AppleScript fits a specific niche: deep control of scriptable apps with a stable, documented interface. Other tools are better for file processing, quick personal automations or cross-platform work.
| Tool | Main strength | Main weakness |
|---|---|---|
| AppleScript | Direct access to app dictionaries | Verbose syntax and inconsistent dictionaries |
| JavaScript for Automation | Familiar JavaScript syntax | Sparse documentation and small community |
| Shell scripting | Fast file and system operations | Cannot control most GUI apps |
| Shortcuts | Visual building and iPhone parity | Limited logic and debugging |
| Automator | Simple workflows without code | Legacy status with few updates |
In practice, these tools are combined rather than chosen exclusively. A common design uses Shortcuts or a launcher as the trigger, AppleScript for the app-specific steps, and shell commands for heavy text or file processing.
Privacy permissions and security controls
Since macOS Mojave, AppleScript is governed by Transparency, Consent and Control (TCC). The first time a script or host app sends Apple events to another app, macOS asks the user to approve Automation permission for that specific pair. GUI scripting additionally requires Accessibility permission, and reading protected locations may need Full Disk Access.
Permissions belong to the process that runs the script, which is often Terminal, Script Editor or a saved applet, not the script file itself. This explains why a script that works in Script Editor fails when launched from cron or from another tool. Applets distributed to other Macs should be signed with codesign and notarized, or Gatekeeper will block them; the xattr command can show the quarantine attribute that triggers this check.
Limitations and common mistakes
AppleScript has a reputation for being easy to read but hard to write, because its natural-language syntax hides strict grammar rules. Most failures come from dictionary quirks, timing and permissions rather than from the language itself.
| Symptom | Cause | Fix |
|---|---|---|
| Error -1743 | Automation permission not granted | Allow it in Privacy and Security settings |
| Error -1728 | Object specifier points to nothing | Check the element exists before using it |
| AppleEvent timed out | App busy longer than 120 seconds | Wrap the call in a with timeout block |
| GUI script breaks after update | Menu or button labels changed | Prefer dictionary commands over UI clicks |
| Works in editor, fails in launchd | Different host process lacks permission | Grant permission to the actual runner |
- Assuming every app is scriptable: many modern apps offer no dictionary at all.
- Relying on
delaystatements instead of checking app state, which makes scripts fragile on slower Macs. - Ignoring that Apple has added few new language features since about 2014; the language is maintained but not actively evolving.
Stripped to the essentials
AppleScript is a way to give written instructions to Mac apps, almost in everyday English. You write something like “tell Mail to check for new messages”, and the app does it as if you had clicked the button yourself.
It is useful for repetitive jobs that would otherwise take dozens of clicks. The Mac asks for your permission before one app is allowed to control another, so nothing runs behind your back.
Where it is applied
A small prepress studio receives about 150 customer PDF files per week that must be checked, renamed and moved into job folders. An operator previously opened each file, noted its page count and dimensions, and filed it by hand, which took roughly five hours a week.
The studio’s technician writes an AppleScript droplet saved as an applet. When files are dropped onto it, the script reads page count and size through a PDF tool’s dictionary, uses do shell script with mdls to fetch metadata, renames each file to the pattern job number, customer and page count, and moves it into the matching folder in Finder. Files that fail a size check are tagged red for manual review.
After a one-time Automation approval for Finder and the PDF app, the weekly intake drops to about twenty minutes, and filing errors, which previously occurred several times a month, practically disappear.