Run Automator workflow or shell script at application launch/shutdown

by Robin Trietsch   Last Updated October 03, 2018 01:12 AM

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!



Answers 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.

Mateus Ribeiro
Mateus Ribeiro
October 03, 2018 00:44 AM

Related Questions


Automator: Run TextEdit as Root

Updated September 12, 2017 00:12 AM

Can Mac App Store installs & upgrades be automated?

Updated September 22, 2018 16:12 PM

Use Automator to run MongoDB and Node.js app on startup

Updated September 25, 2017 11:12 AM