Terminal 101: Running AppleScripts from the Terminal

Every Monday, we'll show you how to do something new and simple with Apple's built-in command line application.

Every Monday, we'll show you how to do something new and simple with Apple's built-in command line application. You don't need any fancy software, or a knowledge of coding to do any of these. All you need is a keyboard to type 'em out!

We’ve covered a few AppleScripts in the past, but we've taught you about running these scripts from within the AppleScript editor. While that is the ideal place to test those scripts, it’s not the best way to run them. That’s where this Terminal 101 tip comes in: you can also run almost any AppleScript from within the Terminal. Read on to find out how.

Preparing Your AppleScript

To prepare your AppleScript to run in the Finder, you’ll want to open it in the AppleScript Editor (located in /Application/Utilities). Once opened, click File > Save As. In the save dialog, type in the name of the file, and then choose the save location. You’ll want to select “Script” from the File Format drop-down menu. When you’re done, click Save.

Running the AppleScript from a File

If you saved your AppleScript as a “.scpt” file, then you can directly run it in the Terminal by typing in the following command:

osacript ScriptName.scpt


Replace “ScriptName.scpt” with the path and name of the AppleScript file that you wish to run.

Running the AppleScript in the Terminal

You can also run an AppleScript in the Terminal without having a script file. You’ll use the same command with -e option, and will also include the intended script in single-quotes after the command, like this:

osascript -e 'tell application "Twitter" to quit'


Cory Bohon is a freelance technology writer, indie Mac and iOS developer, and amateur photographer. Follow this article's author, Cory Bohon on Twitter.