How to execute AppleScript commands on the command line
If you work on a Mac you can use AppleScript to automate many of your applications as well as the built-in OS X functionality.
Any AppleScript command can be run from the Terminal by using the osascript utility; one such command that I’ve found useful is to launch the Mac OS X Screensaver.
To execute an AppleScript that will launch the Mac OS X Screensaver from the Terminal, open a new Terminal window and enter the following command:
osascript -e 'tell application id "com.apple.ScreenSaver.Engine"
to launch'
You can create a bash script to run the command by creating a new file (in this example, “launch_screensaver.sh”) containing the following:
#!/bin/bash
osascript -e 'tell application id "com.apple.ScreenSaver.Engine"
to launch'
... and then running the bash script by opening a new Terminal window, switching to the directory containing the script, and entering the following command:
./launch_screensaver.sh