0

As the title says, I'm looking for a way to run an Automator workflow (or a shell script) when I launch a specific application. When I shut down the application, I want to run another workflow/shell script. How do I achieve this?

Any help is much appreciated!

  • The only method I've found for doing this is polling for active applications. You'd think there'd be a way, but I have yet to find one. – William T Froggard Oct 14 '15 at 21:01
  • You could always use a script [saved as an app] to do the launching. It will then wait patiently until it quits before carrying on. [It will show not responding during that time, but does actually work. I use the method on apps that stay open for days sometimes, they still get tidied up at the end, so long as I don't reboot & forget to quit first. – Tetsujin Oct 14 '15 at 21:24
1

To keep tracking if an app is running you need to use a background loop. I don't know if there is another method but this will work, although it will eat a little bit of your memory. The loop will keep waiting until you open the application, and then it will wait for you to quit.

Save your workflow as an application and set it to run on startup. As your first action run an Applescript like this:


repeat until application "TextEdit" is running -- change for the app you want
    delay 1 -- it will check every one second for the app
end repeat
delay 3 -- you can change this value if the app will take some time to get ready
if application "TextEdit" is running then 
    -- Your code for starting here
end if

you can set other actions after this or just use applescript.

At the end of the workflow place another action running Applescript:


repeat until application "TextEdit" is not running -- change here too
    delay 1 -- it will check every one second if the app is gone
end repeat
delay 3 -- you can change this value if the app will take some time to vanish
if application "TextEdit" is not running then 
    -- Your code for quitting here
end if

Again you can set other actions below.

Let me know if you have specific goals and we can work to improve this workflow.

You must log in to answer this question.

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