Monday, May 28, 2012

Triggering a Shell Script from Application Dock in OSX

As I have commented in the previous post, sometimes you need to frequently run a set of commands or a shell script from the Terminal application, for example to activate your favorite USB WiFi adapter. There are two options of going around that - either set the script to execute on startup, or to configure the script as an application which you can just trigger with a single mouse click. I will discuss the latter as it makes more sense for ad-hoc shell scripts.

The first thing you need to do is open up the Automator application which is installed by default on OSX:


Automator enables you to configure new applications - in fact once you open up Automator you need to choose the Application template:


Next you need to click on Library and find the "Run AppleScript" workflow:



This will let you configure a new AppleScript where you can put the commands or shell script to run. Note that if your script needs to be run under sudo, you need to use the "with administrator privileges" clause:


Now just save the file (this will be saved as an application) - You can drag this application to your dock which you can execute at any time.
Post a Comment