1

I was reading a post about using Bittorrent Sync on OS X that includes a launchd plist that's supposed to keep the app running in the event that it crashes. It doesn't seem to work, though, since I've had the app crash and not relaunch. I'm looking for help fixing the plist.

The plist looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>KeepAlive</key>
    <dict>
        <key>Crashed</key>
        <true/>
        <key>SuccessfulExit</key>
        <false/>
    </dict>
    <key>Label</key>
    <string>sync.com.tjluoma.bittorrentsync</string>
    <key>ProgramArguments</key>
    <array>
        <string>/usr/bin/open</string>
        <string>-W</string>
        <string>-a</string>
        <string>BitTorrent Sync</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
</dict>
</plist>

The "clever" bit is using /usr/bin/open to launch the app, with -W to make sure that open waits for the app to exit. But I think that's also why it doesn't actually work. If I'm reading this right, the app will only relaunch if /usr/bin/open crashes, not if Bittorrent Sync crashes. For the above approach to work, open would need to return error status if the app it opened had crashed (and this does not happen).

I know I could fix this by dropping open and instead hard coding the path to the executable as /Applications/BitTorrent Sync.app/Contents/MacOS/BitTorrent Sync. But is there an alternative that doesn't require hard-coding the full path? Using open would be elegant, if it worked.

1

It was as I expected. The version in the question doesn't re-launch the app, because /usr/bin/open doesn't return an error status when the app crashes. I wasn't able to find a better way than hard-coding the path to the executable, so I'm now using the following.

<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
        <key>KeepAlive</key>
        <dict>
                <key>Crashed</key>
                <true/>
                <key>SuccessfulExit</key>
                <false/>
        </dict>
        <key>Label</key>
        <string>com.getsync.bittorrentsync</string>
        <key>Program</key>
        <string>/Applications/BitTorrent Sync.app/Contents/MacOS/BitTorrent Sync</string>
        <key>RunAtLoad</key>
        <true/>
</dict>
</plist>

I've verified that this does successfully re-launch the app if it crashes.

A more easily downloadable version of this can be found at https://gist.github.com/atomicbird/ff2de46a594cdb5c8e69

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .