Executing OS X Commands on Login
This is a general tutorial on how to execute line commands on OS X startup, but the currently relevant example is Synergy.
Having recently discovered Synergy, I received a few questions on how to get the latest copy of Synergy (1.1.8) to start when logging into OS X. Since Synergy does not currently have an OS X gui, you need to use shell scripts. I don’t know if this is the “best” way to code an OS X shell script, but I promise it’s easy and it works. If you know of something better, I’m all ears.
Determine the Command You Want to Run
In this case, we want to start the Synergy server. I keep my Synergy folder in /Applications so the full command I would like to run is
/Applications/synergy-1.1.8/synergys
It doesn’t matter if the command you want to use is, just test it out in the Terminal to make sure it does indeed do what you want.
Create the Script
Open up a text editor and make sure it saves what you write as plain old text. TextEdit should work fine. Your file should only have two lines in it.
#!/bin/sh
/Applications/synergy-1.1.8/synergys
Now save it as “localServerStart.sh” or something that makes sense to you. I prefer to use the .sh extension simply because it helps me remember I’m using sh as opposed to some other *sh. In the end, it doesn’t matter what you name the script.
Make the Script Executable
Open Terminal and navigate to where you saved the script. Substitute “<yourfile>” for the name of your script. I would type localServerStart.sh instead of “<yourfile>“. Type the following command and press enter.
chmod u+x <yourfile>
Associate Script to Terminal
Locate the script in Finder and choose “Open With” from the contextual menu. Check the “Always Open With” checkbox, and select Terminal as your application. Click “Open”. If the script doesn’t run properly after doing this, go back and make sure you didn’t miss a step.
Add Script to Startup Items
Finally, open your System Preferences and go to Accounts. Highlight the account you’d like Synergy to startup under and click the Startup Items tab. Click the plus sign directly under Startup Items and add the script to the list.
That’s it. :)