1

Since uTorrent to my best of knowledge doesen't support a daemon/server mode, I would like to add it to launchd to start upon login (and restart after a potential crash), but without the app window opening.

Is there a way to do this?

1 Answer 1

3

Try saving a plist like this as ~/Library/LaunchAgents/utorrent.plist:

<?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>utorrent</string>
    <key>ProgramArguments</key>
    <array>
        <string>open</string>
        <string>-gjWa</string>
        <string>uTorrent</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    <key>KeepAlive</key>
    <true/>
</dict>
</plist>

It can be loaded with launchctl load ~/Library/LaunchAgents/utorrent.plist or by logging out and back in.

  -W, --wait-apps   Blocks until the used applications are closed (even if they were already running).
  -j, --hide        Launches the app hidden.
  -g, --background  Does not bring the application to the foreground.

/Applications/uTorrent.app/Contents/MacOS/uTorrent would display a visible uTorrent window if uTorrent wasn't already running.

Another option might be to add a line like this to crontab:

*/5 * * * * pgrep -xq uTorrent && osascript -e 'launch app "uTorrent"' || open -gja uTorrent

open -gj shows the main window if uTorrent is open but has no visible windows. launch shows the main window if uTorrent is not open.

Programs run from crontab are run in the system security / login session. For example Mail can't access keychains if it is opened by cron.

5
  • I have no problems creating the plist file. In fact it is already running. My problem is the GUI window, which auto-opens upon launch and there seems to be no app-pref setting to prevent it from doing so. My core question was, if there is way to open the app without the window opening.
    – OvQ
    Commented Jun 8, 2013 at 14:14
  • Way to go...... Lauri :)
    – Ruskes
    Commented Jun 8, 2013 at 14:59
  • The altered plist works like a charm! Thank you! I have one more question: Is this correct: the -Wa flag prevents launched to launch the app, if it is already running, effectively preventing the app to run twice?
    – OvQ
    Commented Jun 8, 2013 at 15:56
  • ...I have been checking out the manpage for open, but it dosen't mention your -j flag.
    – OvQ
    Commented Jun 8, 2013 at 16:10
  • -W blocks the open command until uTorrent is terminated, so that launchd runs the open command again if uTorrent is terminated. -j was added in 10.8, and it is only shown in the help message.
    – Lri
    Commented Jun 8, 2013 at 16:16

You must log in to answer this question.

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