Mac: Run Script before or after Wake from Sleep

I have a few scripts that I want want my macbook to run just before I put it to sleep (by simply closing the lid).

To achive this I did the following:

  1. I installed sleepwatcher via brew
    brew install sleepwatcher
  2. Then I copied the launchd files to the ~/Library/LauchAgents directory
    cp /usr/local/Cellar/sleepwatcher/2.2/de.bernhard-baehr.sleepwatcher-20compatibility-localuser.plist ~/Library/LaunchAgents
  3. I restarted my Macbook and created the ~/.sleep script which contains the commands that will run before sleep.. (You could also create a ~/.wakeup script that runs when the mac wakes up.)

Source: EchoDitto Labs, Stack Overflow

Comments are closed.