Autostarting the Synergy Server on Mac OS X using launchd

Synergy is a terrific tool that allows multiple machines on a network to share one set of Mouse/Keyboard.
The typical application is probably a setup like mine: since I bought a Dell 2407WFP (I really recommend this store, the prices are amazing and the owner is a very nice and helpful guy) a few months ago, I couldn't bring myself to stare a my laptops crappy screen any longer. Placed right under the monitor, it uses the Dell as its display now, connected by VGA while my Mac mini is connected by DVI. Switching inputs on the Monitor isn't a problem but actually operating the laptop with its lid closed is kinda difficult. Since both computers are in my LAN, I use Synergy to share the Mac's Mouse and Keyboard with the Laptop.

Manually starting the Synergy server on the mac works but is quite unelegant. Open Terminal, launch synergys, quit Terminal. The instructions for launching Synergy automatically on the Synergy homepage are from the time before Mac OS X 10.4 and don't use launchd for launching, relying on LoginHooks or StartupItems instead.

Launching via launchd is neither difficult nor very original but since Information on this is a little hard to find, I wanted to share my synergy launchd here:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>net.sourceforge.syngery2</string>
    <key>OnDemand</key>
    <false/>
    <key>ProgramArguments</key>
    <array>
        <string>/usr/local/bin/synergys</string>
        <string>--no-daemon</string>
        <string>--no-restart</string>
        <string>--debug</string>
        <string>WARNING</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    <key>ServiceDescription</key>
    <string>Synergy Server</string>
</dict>
</plist>

The first program argument has to be adjusted for your system of course. Place this file in /Library/LaunchAgents. I deliberately did not make this an OnDemand Item since that involves fiddling with /etc/services.
Synergy starts quickly and doesn't use many resources, so this shouldn't be a problem.

Getting the keys to work correctly

The ALT and WIN keys don't work correctly when connecting a Windows client to a Mac server. To fix this, add these lines to your windows client in the screens section in /etc/synergy.conf:

  alt = super
  super = alt

27 Responses to “Autostarting the Synergy Server on Mac OS X using launchd”

  1. Larry says:

    I’ve tried using launchd with synergys for a long time. Seems as though it worked for awhile, but now whenever I try to run it from launchd it dies and restarts quickly many times, then launchd gives up on it. I tried modifiying my plist to look like yours (only significant changes were that I was using ‘-f‘ instead of ‘--no-daemon‘ and was not using ‘--no-restart‘. I also had a couple of string args to use ”--config /usr/local/etc/synergy.conf“. Still happens the same way.

    Aug 21 16:09:16 habu-sf launchd[23049]: net.sourceforge.synergys: will restart in 10 seconds
    Aug 21 16:09:26 habu-sf synergys[23339]: Can't register screen saver connection 'com.apple.ScreenSaverDaemon'
    Aug 21 16:09:26 habu-sf launchd[23049]: net.sourceforge.synergys: exited abnormally: Abort trap
    Aug 21 16:09:26 habu-sf launchd[23049]: net.sourceforge.synergys: respawning too quickly! throttling
    Aug 21 16:09:26 habu-sf launchd[23049]: net.sourceforge.synergys: 1 more failure without living at least 60 seconds will cause job removal
    Aug 21 16:09:26 habu-sf launchd[23049]: net.sourceforge.synergys: will restart in 10 seconds
    Aug 21 16:09:37 habu-sf synergys[23342]: Can't register screen saver connection 'com.apple.ScreenSaverDaemon'
    Aug 21 16:09:37 habu-sf launchd[23049]: net.sourceforge.synergys: exited abnormally: Abort trap
    Aug 21 16:09:37 habu-sf launchd[23049]: net.sourceforge.synergys: respawning too quickly! throttling
    Aug 21 16:09:37 habu-sf launchd[23049]: net.sourceforge.synergys: too many failures in succession

    The ‘com.apple.ScreenSaverDaemon‘ bit is new, but I was seeing the same errors before aside from that, so that’s a red herring.

    I’m back to running synergy manually from the command line.

    Anyone seen anything like this?

  2. Jan says:

    --no-restart is mandatory if you follow the Launchd Guidelines.

    The screensaver issue never happened to me, alas I don’t have a screensaver activated on my mac (which acts as the server). Try deactivating it, maybe that helps.

    Where have you placed your plist file?

  3. Larry says:

    I have the plist file in ~/Library/LaunchAgents. I’ve always had it there.

    As I said, when I first set up launchd to run synergys, it worked well. Then at some point (possibly after a system upgrade) it started running in to the problem.

    I’ll try disabling the ScreenSaver just to see what happens, but I’ve seen it fail without the ScreenSaver error anyway.

  4. Larry says:

    Interesting. When I disabled the screen saver and logged out and back in, Synergys ran with no errors. I set up the screen saver again, and even activated it again. No errors from synergys. Must be a timing issue. Since I have to run the screen saver, I’ll try and juggle things around and see what I can come up with. I know that I’ve seen the problem without seeing the ScreenSaver error — particularly when doing a manual ‘launchctl load’.

    I can now do a manual unload and a manual load without getting the error — and with the screen saver activated. I do get a “Workaround Bonjour: Unknown error: 0″, but I’ve always had that and it appears harmless.

    So I still don’t know what causes it to work sometimes and not others. Sigh.

  5. Jan says:

    Well then, how about trying to set this up as a system-wide startup-item (/Library/LaunchAgents instead of ~/Library/LaunchAgents)?

    That could solve timing issues. I haven’t tried this out here, but it seems to be the biggest difference between your setup and mine.

    And this might help too.

  6. Larry says:

    I’ll give that a shot. And here is a series without the screen saver — same as before otherwise.
    Aug 22 08:07:23 habu-sf launchd[25164]: net.sourceforge.synergys: 2 more failures without living at least 60 seconds will cause job removal
    Aug 22 08:07:23 habu-sf launchd[25164]: net.sourceforge.synergys: will restart in 10 seconds
    Aug 22 08:07:34 habu-sf launchd[25164]: net.sourceforge.synergys: exited abnormally: Abort trap
    Aug 22 08:07:34 habu-sf launchd[25164]: net.sourceforge.synergys: respawning too quickly! throttling
    Aug 22 08:07:34 habu-sf launchd[25164]: net.sourceforge.synergys: 1 more failure without living at least 60 seconds will cause job removal
    Aug 22 08:07:34 habu-sf launchd[25164]: net.sourceforge.synergys: will restart in 10 seconds
    Aug 22 08:07:44 habu-sf launchd[25164]: net.sourceforge.synergys: exited abnormally: Abort trap
    Aug 22 08:07:44 habu-sf launchd[25164]: net.sourceforge.synergys: respawning too quickly! throttling
    Aug 22 08:07:44 habu-sf launchd[25164]: net.sourceforge.synergys: too many failures in succession

    I’ll try moving to the system LaunchAgents and see if that makes a difference.

  7. Larry says:

    Hm. Running from /Library/LaunchAgents seems to have worked, at least for the first try. It shows a clean start in system.log and is running properly.

    That may be all that it takes to fix the problem. Curious, but not inexplicable. Thanks for the suggestion. Should have tried it myself, I suppose.

    If it turns out that it doesn’t work consistently, I’ll let you know — just for your information.

  8. Kasey says:

    The Alt and Win keys are reversed on purpose to make the keys the same location as they are on Windows keyboard.

    This is because you are normally accustomed to using a Windows keyboard layout on a Windows machine.

    I reversed them at first also, but later realized why they are that way and changed back so I could still be used to the Windows layout when I had to use PCs.

    If you don’t often have to do that, then it makes sense to reverse them so you are used to the Mac layout on Windows when you use Parallels / Fusion / BootCamp on your Mac.

  9. […] If you are running a Synergy server on OS X 10.5 please look here. […]

  10. Cody Robbins says:

    Thanks, this gets Synergy working for me on Leopard again!

    Since no one explicitly states it anywhere, you can manually have launchd start Synergy after you set this all up, if you don’t want to restart your computer:

    launchctl load /Library/LaunchAgents/net.sourceforge.synergy2

    You might also want to delete the login hook you previously had, if you were, like me, starting Synergy in Tiger using the second method listed on the autostarting page on the Synergy website:

    Make sure your login hook is still the one in place.

    defaults read com.apple.loginwindow LoginHook
    Delete it if so.

    sudo mv /Library/LoginWindow/LoginHook ~/.Trash
    defaults delete com.apple.loginwindow LoginHook

  11. Marc Limotte says:

    Thanks for the tips, Jan.

    Cody, I used your command to manually start:

    launchctl load /Library/LaunchAgents/net.sourceforge.synergy2

    But launchd complained about file not found. I had to do this instead:

    launchctl load /Library/LaunchAgents/net.sourceforge.synergy2.plist

  12. Will says:

    Thanks for the tips, all. I have another issue, that I wonder if anyone else is seeing?

    I’m running synergys on a linux server, and my mac is a client. I Have set up /Library/LaunchAgents/net.sourceforge.synergy2, as described above.

    On launch (either at system boot or using launchctl), I get the following printed to system.log:

    synergyc[2085]: Can’t register screen saver connection ‘com.apple.ScreenSaverDaemon’

    Synergy still works, but copy & paste between my 2 boxes doesn’t.

    I get the same thing if I fire off synergy using screen to background it (screen -dm ).

    If, however, I use a foreground process, in a terminal, to fire off the same command
    If i run synergy from the command line, I get no errors, and copy and paste works fine.

    Any ideas, anyone? It’d be awesome to have copy & paste back without running synergy explicitly from the commandline!

    Thanks,

    Will.

  13. Andrew Roth says:

    Hi,

    I can get synergy to start up, and even see other clients connect to it, but when I try to move the mouse to the other screen it doesn’t work. If I launchctl stop synergys, launchctl start synergys it works. Wtf?

  14. Chris says:

    Hi,

    What am I doing wrong? All I ever get from this is “opendir() failed to open the directory” and “nothing found to load” I think I have everything in the right places. I originally added a few lines to add in my synergy.conf file since I had it in the /usr/local/bin path instead of /etc/ does it need to be in /etc/ for this to work? I’m a bit of a newb/dabbler.

    It looks like a much more elegant solution since the LoginHook always stalls my login until I have to restart in single user mode and delete it. Very frustrating :)

    Thoughts?

  15. Chris says:

    This is the .plist I am currently using. Oh yah – Mac OS X 10.4.11

    Label
    net.sourceforge.syngery2
    OnDemand

    ProgramArguments

    /usr/local/bin/synergys
    -f
    –config
    /usr/local/bin/synergy.conf
    -no-daemon
    -no-restart
    -debug
    WARNING

    RunAtLoad

    ServiceDescription
    Synergy Server

  16. Chris says:

    my apologies – last comment I swear – the copy and paste was stripped – it does have all the proper syntax as I have been doing it in the Property List Editor.

  17. Steve says:

    For the no-daemon and no-restart I had to put two dashes ‘-‘ instead of one…

  18. ryall says:

    For the record, don’t copy and paste from the plist text above. It puts in some weird dashes for the arguments (-no-daemon etc). Took me a long while to figure out why things weren’t working…

  19. georg says:

    I have the same problem as Andrew. Any ideas to this?

  20. […] on OS X Leopard (and starting it manually is kind of a hassle). My approach is based on Jan Varwig’s instructions, which needed yet more modification for my purposes. Having configured synergy.conf, I set the […]

  21. Jan says:

    Just a quick note to all people having problems:
    I haven’t used Synergy in 1,5 years. I use Macs exclusively now and between them Teleport works just way better. So I can’t help you with any trouble you might experience but since this page is quite popular you might find other people who might be able to assist or share experiences in this very comment thread which I’m going to leave open.
    You might be interested in subscribing to it via the RSS2 link at the bottom of this page.

  22. Gee, when you copy and past, make sure you replace all dashes in the options such as “–no-daemon”

    The copy and past adds characters that look like dashes, but are not for this type of script.

  23. Also, you can copy your configuration into ~/.synergy.conf and so no need to identify the config file.

  24. job says:

    Maybe someone can use this (although not perfect). This is how I start Synergy client on my mac with Leopard OS:
    File: /Applications/synergy/synergyclientstart
    DIRECTORY=/Applications/synergy/synergy-1.3.1
    $DIRECTORY/synergyc -f -d WARNING 192.168.3.3
    exit 0

    File: /Library/LaunchAgents/net.sourceforge.synergy2.plist

    Label
    net.sourceforge.syngery2
    KeepAlive

    ProgramArguments

    /Applications/synergy/synergyclientstart
    –no-daemon
    –no-restart
    –debug
    WARNING

    RunAtLoad

    ServiceDescription
    Synergy Client

  25. Lincoln Short says:

    thanks heaps for the swapping around of the alt & super keys in the config file (see above).
    I’ve been searching for this fix for over 3 days, I have a mac keyboard on a windows box thats being the server and I keep trying different drivers and key mappings and in the end this resolved it thats heaps!

  26. Chris says:

    Everything worked perfectly for me by the original instructions, except for the “Program Arguments” section only shows one hyphen in front of no-daemon, no-restart and debug. It should actually be just as you would type from terminal:

    --no-daemon
    --no-restart
    --debug WARNING
    

    Thanks for taking the time to explain how to get this working properly for 10.5+

  27. […] de panique, d’après Jan Varwig et la doc d’Apple les StartupItems sont depracated et les scripts sont gérés par lauchnd. Donc […]