PDA

View Full Version : Execute something when an app quits?


chucker
2007-03-03, 03:29
Is there any hook mechanism (launchd, Folder Actions, watchdog, whateverintheworld) that will let me execute a Unix command after a certain application quits? Or, perhaps, when it launches, but before it has done any I/O?

I realize I could do it with InputManagers, but that's hack-ish.

Majost
2007-03-03, 11:55
Couldn't you possibly write a script of some sort (AppleScript, .sh, compiled program, whatever) that would run a command before executing the program? Or after? I don't know how you would bundle it nicely, but I'm sure you could figure that out.

chucker
2007-03-03, 11:59
Couldn't you possibly write a script of some sort (AppleScript, .sh, compiled program, whatever) that would run a command before executing the program? Or after? I don't know how you would bundle it nicely, but I'm sure you could figure that out.

But how would you have it triggered?

Majost
2007-03-03, 12:12
Simply sequentially. If you do a bash shell script, just don't background either process. Once one finishes, the other will execute.

But, like I said, it'll be ugly -- you'd have to get some kind of nice wrapper to go around it so you wouldn't constantly have a terminal shell open or an extra application icon running in your dock.

Matlab has a starter application that simply runs a shell script. It's a fairly nice wrapper that you could use for other stuff, too, I'd imagine. One difficulty would be getting the icon to hide, though.

chucker
2007-03-03, 12:13
Not an option, I'm afraid. I want people to execute the main app as usual without modification, but benefit from the change to it.

Maybe I can do something with launchd watch paths.

chucker
2007-03-03, 12:56
Yeah, a watch path actually solves this particular problem just fine. :)

I'd still like to see a solution to having something hooked in right before an app launches, or right after it quits. Maybe in launchd 2.0.