Launch shell script when app runs?

Hi, I'm new here, so if this is an inappropriate question, or if it's in the wrong forum, please forgive me...


I have downloaded a Mac OS X utility from the internet. It pretty much does what it's supposed to do, so I have no serious complaints. However, when I quit the app, it leaves behind a couple of "agent" processes in the "PrivilegedHelperTools space" which never go away, and I have to use "kill -INT" in the Terminal to get rid of them.


I've had to do this enough that I ended up creating a shell script which does the work for me. It's written as an infinite loop with a "sleep" period after each iteration, so that it effectively becomes a "demon" ... and, I've scheduled it to run at login using launchd/launchctl.


So in effect I've created one demon to look for and kill another demon. Not ideal, to say the least.


What I'd *really* like to do is modify the utilty that I downloaded so that in addition to running its own agents at startup it also launches my script. Then, when I quit the utility, my script would kill the orphaned agents, then quit itself.


Is this possible? And if so, how would I accomplish it?


I can see, after doing "Show Package Contents" in the Finder, that the utility has a Library/LoginItems folder, and in that folder I see the agents that are run, which never go away. I reasoned that I could add my shell script to that folder, and it, too, would run when the application launches. But that does not happen. So I'm guessing I have to edit a plist somewhere?


Any assistance would be most appreciated!


Thanks,

Barry

Replies

The easiest solution would be to just state the name of the tool so someone else could look at it. And maybe contact the developer and ask for a fix.


Otherwise, you are mixing and matching concepts here. Launchd and LoginItems are completely different.


Without knowing any of the pertinent details, all I can tell you is to look at the details under "man launchd.plist". Or maybe look at the "Lingon" app. You can write a launchd script that only launches your task when some other software is or is not running. I expect you could hack something up to look for a change in status when this other app quits and then take action.

Regarding: "...you are mixing and matching concepts here. Launchd and LoginItems are completely different."


Sorry, I was obviously not very clear in my actions or in my intent.


I created a script to remove (kill) the unwanted agents, and used launchd as the means to run my script, and keep it running, as a "demon". I have no trouble creating a demon, and I'm familiar with launchd and with Lingon.


But I would prefer to find a different means than a launchd demon to kill the unwanted agents left behind by the "rogue app". I noted that the app in question launches its agents using "LoginItems". That is, within the Package Contents as shown by the Finder there is a Library/LoginItems folder, with item names matching the agents that I want to kill.


I concluded from this... correct me if I'm wrong... that applications can have their own "login items" separate from login items defined at the user or system level... and that, in the case of applications, "login" is synonymous with "run" (or "launch" (but not in the "launchd" sense)). In other words, application-level "LoginItems" run whenever the application is launched.


Is that correct?


If so, then I want to know if the application-level LoginItems mechanism would be a viable way to run my script? Can I simply add my script to the application bundle (after doing "Show Package Contents"), and then presumably edit a plist file somewhere within the bundle to "register" the script with the application so that it runs, along with the other agents? (In other words, I want to add my script as another "agent" within the app.)


Can this be done? If so, how?


Thanks!

Might have more luck w/this topic by moving your questions to theScripting and Automation forum.


Good luck.