1

Can triggers be set up so that when "App A" starts, another "App B" gets started automatically? Ideally, the solution would send a quit message to "App B" when "App A" quits, but the important part is the launch sequence.

1 Answer 1

1

Save a plist like this as ~/Library/LaunchAgents/test.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>test</string>
  <key>ProgramArguments</key>
  <array>
    <string>bash</string>
    <string>-c</string>
    <string>while sleep 5; do
  if pgrep -x Preview; then
    pgrep -x TextEdit || open -jga TextEdit
  else
    pgrep -x TextEdit &amp;&amp; osascript -e 'quit app "TextEdit"'
  fi
done</string>
  </array>
  <key>RunAtLoad</key>
  <true/>
  <key>KeepAlive</key>
  <true/>
</dict>
</plist>

Then load the plist with launchctl load ~/Library/LaunchAgents/test.plist or by logging out and back in.

open -jg is supposed to open an application hidden and without raising any windows. For some document-based applications like TextEdit, it opens a new visible window if the application is open but has no visible windows.

pgrep and the -j option for open were added in 10.8. The -j option is only shown in the help message and not on the man page.

You must log in to answer this question.

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