0

I was wondering if there was an easy way to launch a specific Application whenever another Application is launched. In other words, I want to launch multiple Applications together as a group.

To be more specific, I have small app that downloads lyrics for the currently playing iTunes track, and another that writes the currently playing track to a file. The problem is, I often forget to launch these apps when I start iTunes. I would like them to open every time I open iTunes.

Any suggestions would be appreciated.

1

Save a plist like this as ~/Library/LaunchAgents/some.label.plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>Label</key>
  <string>some.label</string>
  <key>ProgramArguments</key>
  <array>
    <string>bash</string>
    <string>-c</string>
    <string>if pgrep -x iTunes;then open -jga Some\ Application;open -jga Another\ Application;fi</string>
  </array>
  <key>WatchPaths</key>
  <string>~/Library/Preferences/com.apple.iTunes.plist</string>
</dict>
</plist>

Then run launchctl load ~/Library/LaunchAgents/some.label.plist.

~/Library/Preferences/com.apple.iTunes.plist seems to be modified every time iTunes is opened. The program will be run every time ~/Library/Preferences/com.apple.iTunes.plist is modified (and there's at least 10 seconds from the last run), but it's probably better than running the program for example every 5 seconds.

For most applications, open -jg opens the application hidden and without making it frontmost. For some applications like TextEdit, it opens a new visible window if the application is open but has no windows, but you can use pgrep -x TextEdit||open -jga TextEdit or lsappinfo launch nofront=true launchandhide=true /Applications/TextEdit.app instead.

  • Wowie zowie! This answer is so great I wish I could accept it twice! I've set up the plist and everything is working exactly the way I wanted. – BringMyCakeBack Feb 13 '14 at 19:48
  • After some more testing, it turns out that com.apple.iTunes.plist is also modified every time you reload podcasts or sync devices. To guard against unnecessary Application starting, I added a boolean check to the first line of the command: if pgrep -x iTunes &amp;&amp; ! pgrep -x OtherApp; ... (The &amp is needed to escape the ampersand in the XML plist.) – BringMyCakeBack Feb 19 '14 at 19:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .