What is the programmatical mechanism by which an application can be launched at a result of another one being launched?
E.g. upon launching iTunes, the Last.fm desktop launches too.
Or it is just a question of substituting a “batch file” of some sort?
Note: OS X newbie.
There’s no standard way to specify a dependent app. So, you need to somehow watch the system. You don’t have to actively poll; you need to use some system mechanism to tell you.
To watch for a GUI app to launch, you need to write a background app, get the NSWorkspace’s notification center by
and watch for NSWorkspaceDidLaunchApplicationNotification. See the
Apple doc.To watch for a non-GUI app to launch, you need to use
kqueue. (This is a BSD feature.) See the man page. Typically you have to watchlaunchdtoforkorexecveprocesses. Note that there are multiplelaunchdprocesses, one for root and one for each logged-in users.In any case you need to start automatically the background app you write. There’re many ways to do that.
To watch a file or a directory to change, you can use
launchdagents. See the man page.By the way: the official
Last.fmapp, on its first launch, installsAudioScrobbler.bundleinside~/Library/iTunes/iTunes Plug-ins. iTunes reads all the plug-ins when launched, and the plug-in then launches the Last.fm app. It’s a rather hackish, non-condoned usage of the interface, because the plug-in is for the visualizer. See Apple doc.