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:
- I installed sleepwatcher via brew
brew install sleepwatcher - 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 - 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