View Full Version : Killing an app by name?
jnhager
02-12-2002, 09:58 PM
I would like to use the cron command to start a Mac OSX GUI program from the terminal automatically at a certain date and time and then shut it down at a certain date and time. I would like to know a terminal command that would shutdown that program specifically.
I have tried to do this with the kill command, but I am having trouble. Is there a way to do this with the grep command? I have also tried to install killall command and use that but it cannot find the process. Where would I put the killall command and how do I use it properly to kill a specific process.
Any help would be great.
Jnhager
jnhager
02-12-2002, 10:02 PM
Would an applescript help me with this problem? And if so what is the applescript command/ applescript help site?
mervTormel
02-12-2002, 10:40 PM
a shell script hooked into cron can do this pretty good.
first, you need to be able to find thee process id (pid) that you're looking for. here's a pretty good start at that.
% ps axww | grep -i "[a]ppname"
e.g.,
% ps axww | grep -i "[i]tunes"
19990 ?? S 0:00.43 /Applications/iTunes.app/Contents/Resources/iTunesHelper.app/Contents/MacOS/iTunesHelper /Applications/iTunes.app/Contents/Resources/iTunesHelper.app/Contents/MacOS/iTunesHelper -psn_0_917505
20016 ?? S 56:44.68 /Applications/iTunes.app/Contents/MacOS/iTunes /Applications/iTunes.app/Contents/MacOS/iTunes -psn_0_3276801
whoops. too many processes. now, refine it to get the right one.
% ps axww | grep -i "[i]tunes " # <- note the space after tunes
20016 ?? S 56:47.42 /Applications/iTunes.app/Contents/MacOS/iTunes /Applications/iTunes.app/Contents/MacOS/iTunes -psn_0_3276801
okay? now just get the pid so you can pass it as the arg to kill.
% ps axww | grep -i "[i]tunes " | awk '{print $1}'
20016
then redirect the output of that with the backquotes command substitution notation.
% kill `ps axww | grep -i "[i]tunes " | awk '{print $1}'`
[ edit: urp! thanks, paul. % kill `% ps axww | grep -i "[i]tunes " | awk '{print $1}'` ]
test that out on a trivial app, then promote it to testing on your target app, then submit to cron.
you'll definitely want to make this benign by assuring your app name is unique and isn't anything close to a critical process name, right?
let us know if that's kinda what you're fishing for.
jnhager
02-12-2002, 11:46 PM
That is exactly what I am looking for. Thank you.
pmccann
02-13-2002, 02:09 AM
At the risk of stating the bleeding obvious... well, OK, it's a newcomers forum, so I'm willing to take that risk. If you're cutting and pasting mT's lovely death script and can't see what's causing it to fail, you'll just need to remove the prompt symbol from inside the backticks. So it should read
% kill `ps axww | grep -i "[i]tunes " | awk '{print $1}'`
where (reread my first sentence!) the "%" at the start of the line is your unix prompt and not part of the command.
Cheers,
Paul
Show me the way to go home...
I'm tired and I want to go to bed...
Thanks, pmccann
Cheers...
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.