Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I have an application that opens when I login.

Is there a way to relaunch it automatically if it crashes or if I close it inadvertently? (the application in question is Transmission if there is any solution specific to this app)

In a perfect world, it could even be launched even without me opening a session.

thanks.

share|improve this question
    
Duplicate of / similar to: apple.stackexchange.com/questions/3030/… –  user588 Sep 3 '12 at 15:59

3 Answers 3

up vote 6 down vote accepted

Here is my launchd script to keep SomeApp always running. It is in ~/Library/LaunchAgents/ and called SomeApp.restart.plist

<?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>RunAtLoad</key>  
        <true/>  
        <key>KeepAlive</key>
        <true/>
        <key>Label</key>
        <string>SomeApp.restart</string>
        <key>ProgramArguments</key>
        <array>
                <string>/path/to/SomeApp.app/Contents/MacOS/SomeApp</string>
        </array>
</dict>
</plist>

Load it once with

launchctl load ~/Library/LaunchAgents/SomeApp.restart.plist

Launchctl will run this after reboots.

  • RunAtLoad will launch the application the first time launchctl runs this
  • KeepAlive will restart it if the application quits (CMD+Q or crash)

Should run forever. If you want a GUI tool to help, Lingon works even though development has stopped.

share|improve this answer
1  
Lingon and launchd go together like peanut butter and chocolate, only better. –  bmike Jul 14 '11 at 19:42
    
Lingon 3 is in the App Store now as well, but it's seriously crippled. v2.1.1 at sourceforge.net/projects/lingon/files/Lingon/2.1.1 is way better. –  neu242 Sep 3 '12 at 7:25

You could write a launchd script to do it. Launchd can watch for applications and restart them if they disappear. I might have one somewhere if you are interested.

Updated with an example...

See mankoff's example. Here's mine, it's slightly different but works the same...

<?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>RunAtLoad</key>  
    <true/>  
    <key>KeepAlive</key>  
    <true/>  
    <key>Label</key>  
    <string>keep.it.running</string>  
    <key>Program</key>  
    <string>/Applications/Address Book.app/Contents/MacOS/Address Book</string>  
</dict>  
</plist>  
share|improve this answer
    
This is something i can explore. Could you please send me an example? thx –  Pierre Aug 31 '10 at 11:42
    
Deleted my comment because i couldn't format the code. –  Henry Sep 1 '10 at 1:05
    
Sorry I accepted the other answer because the script seemed more complete and there was the reference to Lingon. But you were the first to provide the right answer, so thanks for that ;) –  Pierre Sep 1 '10 at 9:23

You can open applications on the background with open -jg or the launch command in AppleScript.

#!/bin/bash

open -jg -a FastScripts -a Mail
osascript -e 'launch app "Alfred"'

KeepAlive is not needed. RunAtLoad would also run the program on the zeroth interval.

<?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>Label</key>
    <string>com.stackexchange.apple.837</string>
    <key>Program</key>
    <string>/Users/username/Library/Scripts/open applications.sh</string>
    <key>StartInterval</key>
    <integer>1</integer>
</dict>
</plist>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.