Using Applescript to Start a Unix Application.


You sometimes want a Unix application to run automatically when the computer starts up. An example is the excellent open source application
Synergy which allows you to control several computers from a single console via a network. Whether the Mac is the master machine or a slave, you'll want Synergy active as soon as the machine is switched on.

Synergy isn't a GUI application but runs from the Unix command line. The default method of starting it is to open a terminal window and type in the command to start it...





Now you could put this command into a shell script and add it to the start up files but on a Mac this isn't all that neat. There is, however a better way and that's to use Applescript.


OS-X comes with Applescript installed and all you need to do is look for the Script Editor application which lives in Applications | Applescript on your startup disk. This is not only an editor but a controller for the Applescript compiler so everything's in one place.

The command we need to run a Unix programme is do shell script and here's the complete command to run Synergy as a server...





It's simple enough, isn't it? The only thing you need to note is that you MUST give the complete path for the command and any arguments unless all your paths are already set up for the root user. Even if they are, full paths are probably a good idea for future maintainability.

You'll want to save the script and then you'll want to convert it to an application. Having saved the script in the default (script) mode , which will crate a file with the extension .scpt do save as and select Application to build a runable programme...





We're nearly there now. The last part of the job is to add this script to the list of items to be started when you log on to your computer. (Even if you're the sole registered user, OS-X still goes through a log-in process when it starts up.)

The way to do this, is to invoke System Preferences | System | Accounts | Startup Items,
click the '+' under the list of items to start up and add your command to the list as we've done here...





Close System preferences and the job is done. From now on, whenever you start up, Synergy will start up automatically. You can use this technique to run any Unix command but be aware that many commands will already be running, such as the Apache web server which forms the basis of Apple's 'Personal Web Server'.

Find out more by searching Google here...

Google