Close iTunes (or other apps) after a timeout period
Apr 01, '09 07:30:01AM
Contributed by: uudens
You can use Terminal to close iTunes (or any other application) after a timeout period. It can be convenient if you don't want to download special programs. Open Terminal, and type in this command:
ping -c 1800 localhost; killall iTunes
The 1800 is the timeout in seconds -- 1,800 seconds is 30 minutes (30min * 60sec/min). Note that killall iTunes will happen one second before your timeout, so if you want exactly 30 minutes, you should enter 1801.
If you don't want to see all the ping packets during the timeout period, you can dump the ping output to null like this:
ping -c 1800 localhost >nul; killall iTunes
Cancel the command by pressing Control-C any time before the timeout occurs
[robg adds: killall is probably the dangerous way to do this. A slightly safer version, which allows the app the opportunity to exit gracefully, would be to replace the killall bits with this: osascript -e "tell application \"iTunes\" to quit". If the program needs you to do anything before quitting (save a document with unsaved changes), it will prompt you (via its normal interface in the GUI) to do so. This safer solution, however, wouldn't be very useful if you're attempting to run this timeout script over a remote login (ssh) connection.]
Comments (14)
Mac OS X Hints
http://hints.macworld.com/article.php?story=20090330013417286