
osascript
osascript is a command-line tool from Apple that lets you run scripts directly from the Terminal on a Mac. It is mainly used to control other programs, automate workflows, or display system messages.
A Mac isn’t only operated with the mouse. You can also send it commands as text — so-called scripts, meaning small programs that carry out instructions step by step. osascript is Apple's tool that launches such scripts directly from the Terminal. The Terminal is a text window where you type commands instead of clicking on icons. osascript mainly supports two languages for this: AppleScript, which was developed specifically for Mac automation, and JavaScript for Automation, or JXA for short, which is based on the widely used programming language JavaScript. Both languages can address and control other programs on the Mac, as if you were clicking yourself.
osascript as a lever for Mac automation
Many programs on the Mac provide an interface through which they can be controlled from the outside. osascript uses exactly this interface. With it, you can, for example, instruct Safari to open a specific website, or tell iTunes or Music to pause a song — all without touching the app itself.
This is especially useful when you need to perform the same task over and over again. Instead of manually launching and setting up the same five apps every morning, you write it down once as a script and start it with a single command. Time can be saved systematically this way. In addition, osascript can be combined with other tools in the Terminal, which enables more complex workflows.
How osascript executes a script
The simplest way is a direct command in the Terminal: you write osascript -e, followed by the actual script code in quotation marks. The -e stands for “evaluate”. A classic example is: osascript -e 'display dialog “Hello World”' — this immediately opens a dialog window on the Mac screen with the text “Hello World”.
Alternatively, longer scripts are saved in a file with the extension .scpt or .applescript, and the filename is passed to osascript. The tool then reads the file and executes it. In the background, osascript communicates with what is known as the Open Scripting Architecture — the system Apple built into macOS so that programs can be controlled from the outside at all. Without this infrastructure, every app would be a closed island.
It’s important to note that not every app allows this kind of control. An app must explicitly be “scriptable” and offer what is called a dictionary — a kind of lexicon that describes which commands it understands. Many of Apple’s own apps do this, but with third-party apps this is not a given.
osascript in practice: security tools, AI agents, and malware
In the tech world, osascript appears in very different contexts. System administrators who manage many Macs within a company use it to apply settings automatically across many devices at once. Developers use it to automatically display notifications on screen while building their software.
In AI research, osascript is relevant because AI agents — programs meant to independently carry out tasks on a computer — use it to actually operate the Mac. An agent that is supposed to independently open a browser, fill out a form, and take a screenshot needs exactly these kinds of tools. Researchers working on computer use by AI cannot avoid osascript on the Mac.
However, there is also a dark side: because osascript is so powerful, it regularly appears in security reports. Malware for the Mac uses it to carry out actions unnoticed, fake password dialogs, or steal data. Security tools on the Mac therefore log it when osascript performs unusual actions. Knowing the tool is not a risk — but running it carelessly without understanding the code is.