Pages

Saturday, August 14, 2010

Mac OS X. Keep Safari Alive.

launchctl is a tool allowing to load and unload the daemons on Mac OS X. For example, here I will show how Safari can be re-launched automatically in a case of a crash.
In TextEdit make the following file:

<?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.apple.KeepSafariAlive</string>
<key>ProgramArguments</key>
<array>
<string>/Applications/Safari.app/Contents/MacOS/Safari</string>
</array>
<key>OnDemand</key>
<false/>
</dict>
</plist>

Save it com.apple.KeepSafariAlive.plist in ~/Library/LaunchAgents folder.
Now in Terminal type:
$ launchctl load Library/LaunchAgents/com.apple.KeepSafariAlive.plist
You see Safari running. Try to kill it, for example:
$ killall -9 Safari
To unload the agent use this command:
$ launchctl unload Library/LaunchAgents/com.apple.KeepSafariAlive.plist

This example was taken from this book:

No comments:

Post a Comment