Automate tasks using AppleScript and Terminal on Mac
You can use AppleScript with Terminal to save time or automate repetitive tasks. Terminal is a scriptable app that responds to AppleScript commands. These commands are described in Terminal’s AppleScript dictionary.
View Terminal’s AppleScript dictionary
In the Finder on your Mac, open the /Applications/Utilities folder.
Drag the Terminal app icon onto the Script Editor app icon .
In AppleScript, you can use the
Do Shell Script command to send a UNIX shell script command to Terminal.
Run AppleScript scripts from Terminal
You can run AppleScript scripts from Terminal using the osascript command.
In the Terminal app on your Mac, use the cd command to move into the directory that contains the script you want to run. For example:
% cd ~/Documents/YourScriptDirectory
Enter the osascript command. For example:
% osascript YourScript.scpt