BashScripts.org
http://bashscripts.org/forum/

Run a script whenever an application opens or closes
http://bashscripts.org/forum/viewtopic.php?f=15&t=1034
Page 1 of 1

Author:  ledhed2222 [ Sun Mar 21, 2010 2:14 pm ]
Post subject:  Run a script whenever an application opens or closes

Hello everybody,


I suspect this is either very easy, or not possible the way I envision it.

I'm running OS X and I want to run a script that turns off Time Machine (Mac's backup utility) whenever mission-critical applications open, and then turns it back on when all of them are closed. The goal is not to make a daemon, or have to run a script to open said application, but rather make a script that knows when I open a given application and then executes. Is this possible and if so, what is its rough syntax? Thanks!

Author:  thobbs [ Sun Mar 21, 2010 6:51 pm ]
Post subject:  Re: Run a script whenever an application opens or closes

I'm not familiar with it, but doesn't AppleScript let you do things like this? Might be worth checking out.

Why not make a script that opens the application for you (and handles the Time Machine stuff)? You could give it the normal icon and all that, I'm sure. This might result in upgrade problems though -- I have no idea how OS X handles package management.

And why not a daemon? You could use cron, which is a daemon, to check every minute to see if you are running one of the applications, and if so, call a script to do the Time Machine stuff. Despite running every minute, it's actually very low overhead. If you really need it to handle this in less than a minute after startup, you could make the script check for the application, sleep 30 seconds or so, and then try again.

- thobbs

Page 1 of 1 All times are UTC - 6 hours
© 2000, 2002, 2005, 2007 phpBB Group • http://www.phpbb.com