Ever need to run a shell script from the Mac OS X desktop? In my case, the goal is to add an icon to the desktop or Dock that allows me to click on the script and run it. At first, I took a look at Automator, but that overcomplicates things and really isn’t needed. The actual answer turns out to be much easier.
So here are the steps.
Create your script and debug it from the command line. It might look something like this:
Next, go into Finder and find the script you want to add an icon for. It should have an icon like this.
Make an alias for the script by right-clicking the script icon and choosing “Make Alias”. This makes an alias for your icon.
Move the alias to the Dock or Stack as needed. Now clicking on the icon should run the script.
Fixing up the Script
Setup this way, the script will execute, bring up a terminal window, and quickly disappear. So if you would like a little more information I suggest your update your script like this:
#!/bin/bash ~/path/to/script echo My script ran! sleep 1
echo statement displays a message to the console or in this case terminal window. The
sleep statement determines how long the message will be displayed in seconds. Set the sleep time to whatever you feel is good. This will be the amount of time you can see the message before the terminal window disappears.