This is a website by Willem van Zyl

I'm a project manager, software developer, Apple evangelist and geek from South Africa. I'm passionate about web and mobile application development, usability, productivity, physics, astronomy, science fiction and fantasy.

If you would like to contact me, message me on Twitter or send me an email.

How to execute AppleScript commands on the command line

09 Sep 2010

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
Do you like this? Share it:

Copyright © Geekology 2011. All Rights Reserved.

Hosted by Code. Like. Clockwork.