MacOS X: GetPid("ApplName"); or, how to autokill a process w/o knowing its PID#?

I need to set up a MacOS X routine that will kill and restart a Carbon application that tends to hang. Doing something akin to this in the Terminal:



osascript -e 'tell application "ApplicationName" to quit'


…doesn’t work because the application is hung.

If I were doing it in person, I could get the PID from “top” and then issue the “kill #” command, but since the PID is going to be different and of unpredictable value, I don’t see any easy way of using that.

Unless there exists an easily accessed routine for obtaining the current PID for an application if you happen to know its name?

Alternatively, is there an osa command that will kill off a hung application, as opposed to telling the application to kindly absent itself?

The application, btw, is FileMaker Pro, and the “hung” condition consists of a modal message box coming up on screen stating that “Communication with the Host has been interrupted and cannot be reestablished” with an “OK” button. (It’s a Jaguar thang. FileMaker gets along just fine with 10.1.5 but not with 10.2; unfortunately due to the middleware I’m using I’m stuck with Jaguar on this box). With that message box up, FileMaker is unresponsive to anything and everything, short of someone reaching over with the mouse and clicking the blasted button.

Hmm, that’s another possibility. Is there an OS X version of “Okey Dokey”, a “pusher of default dialog buttons on unattended computers” kind of utility?

My first duplicate OP!

It’s a hamster plot, I tell you!

You want the command killall - it takes the name of the process you want to kill. Type “man killall” in the Terminal for a full introduction.

I just tried this in 10.2.6 6L60 and it worked:

kill ‘ps -uxww | grep <Application name> | grep -v grep | awk ‘{print $2}’’

Didn’t see the other thread, sorry…