Automator workflow to close programme when laptop is closed / goes to sleep

I've got a programme that I use regularly that has a really bad memory leak problem. It seems to be triggered when closing my laptop / putting it to sleep and then waking the laptop up again.

I wondered if it's possible to create an Automator workflow to say "when laptop is closed / when laptop goes to sleep close programme"?


Solution 1:

Yes, this is possible. There are restrictions to performing scripts before sleep but it is possible.

Run a script on sleep

See Possible to run scripts on sleep and wake? for various tools that can run a script before sleep. I wrote, and thus recommend, Power Manager.

For the script, consider using AppleScript instead of Automator. Running an AppleScript before sleep will be simpler. The script could read:

tell application "MemoryLeak.app" to quit