Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Close iTunes (or other apps) after a timeout period Apps
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.]
    •    
  • Currently 2.43 / 5
  You rated: 4 / 5 (7 votes cast)
 
[9,754 views]  

Close iTunes (or other apps) after a timeout period | 14 comments | Create New Account
Click here to return to the 'Close iTunes (or other apps) after a timeout period' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Close iTunes (or other apps) after a timeout period
Authored by: corti on Apr 01, '09 08:09:12AM
Instead of pinging yourself you can use 'sleep' to introduce a delay:
$ sleep 1800; osascript -e "tell application "iTunes" to quit"
Matteo

[ Reply to This | # ]
Close iTunes (or other apps) after a timeout period
Authored by: njnystrom on Apr 01, '09 02:09:14PM
Even better:
sleep 1800 && osascript -e 'tell application "iTunes" to quit'
Using && rather than ; prevents osascript from running if you Ctrl-C during sleep.

---
Nate

[ Reply to This | # ]

Close iTunes (or other apps) after a timeout period
Authored by: momerath on Apr 01, '09 08:10:56AM

Please tell me this hint is an april fool's joke. Pinging localhost for a delay is one of the dumbest things I've ever seen.



[ Reply to This | # ]
Close iTunes (or other apps) after a timeout period
Authored by: mzs on Apr 01, '09 08:18:25AM

Though using select() for a better sleep() is an old Berkley Sockets programmers trick. The ping for a sleep should be on thedailywtf.



[ Reply to This | # ]
Close iTunes (or other apps) after a timeout period
Authored by: scelis on Apr 01, '09 08:58:20AM

This has to be a joke. I'm a particular fan of piping the ping command into 'nul' instead of '/dev/null'...



[ Reply to This | # ]
Close iTunes (or other apps) after a timeout period
Authored by: scelis on Apr 01, '09 09:01:30AM

:s/piping/redirecting the output of



[ Reply to This | # ]
Close iTunes (or other apps) after a timeout period
Authored by: Migs on Apr 02, '09 08:02:14AM

Hi:

What is the difference between piping to Dev Null and just Null?

Migs



[ Reply to This | # ]
Close iTunes (or other apps) after a timeout period
Authored by: scelis on Apr 02, '09 08:20:05AM

Try it. Redirecting some output to 'null' will just create a file called null and write the output there. /dev/null is a special file (also called the null device) which simply discards all data written to it.



[ Reply to This | # ]
Why Terminal?
Authored by: Dr. T on Apr 01, '09 09:50:05AM

I'm a long time Mac user, and I do not understand this infatuation with Terminal. A few simple lines of AppleScript code will safely quit an application after a specified delay period. You can even tell the application to Save before quitting. A slightly more complex script could ask you which application you want to quit and at what time. There's no need to type arcane (and possibly dangerous) commands in Terminal.

Timed quitting of an application also can be accomplished with Automator by making the quit application workflow an iCal plug-in. You set the quit time by telling iCal when to run the workflow. An added advantage here is that you can drag the quit application event to a future date, adjust the time, and run it again.



[ Reply to This | # ]
Why Terminal?
Authored by: kikjou on Apr 01, '09 12:57:09PM

Because once you have learned a little Unix, it is much more elegant and not as crash-prone as a GUI application. For admins: terminal commands can be implemented through ssh, that is remotely, even over a dialup connection while you are at the North Pole. And it does not require specific software to be installed. Speed: deleting or copying files is considerably faster on the command line than in the Finder, and so are other terminal commands with a GUI equivalent.



[ Reply to This | # ]
Close iTunes (or other apps) after a timeout period
Authored by: enigmamf on Apr 01, '09 09:55:11AM
This safer solution, however, wouldn't be very useful if you're attempting to run this timeout script over a remote login (ssh) connection
Huh? osascript works fine via SSH, as long as you are doing something like telling iTunes to quit (if the account you're SSHing with is the same as you are running on the GUI).

[ Reply to This | # ]
Close iTunes (or other apps) after a timeout period
Authored by: ptone on Apr 01, '09 11:23:33AM

Wow - If this isn't an april fools joke (which it really at the end should be labeled as such), it should have never made it through the review process.

just bad all around, mostly covered in previous comments, but I had to add my negative vote.




[ Reply to This | # ]
Close iTunes (or other apps) after a timeout period
Authored by: bozo_z_clown on Apr 01, '09 11:48:33AM

Ok, you got me ... here am I thinking "using ping for a timeout is the dumbest thing I've ever heard of" ... obviously it's an April Fools. Nice one! Kudos to Rob for playing along :-)



[ Reply to This | # ]
Close iTunes (or other apps) after a timeout period
Authored by: maintain1 on Apr 03, '09 02:45:15PM

well it is kinda a covert way of waiting to kill a process. A person would not normally think that the ping command is being used to delay killing off something.



[ Reply to This | # ]