Home
Questions
Reference
Interface
Shell Scripts
Sleep Aid offers the ability to execute shell scripts before the Mac goes to sleep and when it awakes.
Sleep Aid can be configured to use the same shell script for sleep on battery and AC, or to use different scripts for each power source.
Shell scripts are configured in the "Sleep Settings".
Example shell script for freezing an app on sleep.
#!/bin/bash
kill -STOP $(pgrep -f 'Mail')
Example shell script for defrosting an app on sleep.
#!/bin/bash
kill -CONT $(pgrep -f 'Mail')
To use a Shell Script with Sleep Aid
- Use your favorite plain text editor to write out the shell script.
- Save it as ".sh" file with a descriptive name.
- Open "Terminal" and type
chmod +x
and then drag the file into the terminal window, finally press "enter" or "return".
- In the Sleep Aid settings, under the "Shell Scripts" heading, click on the "more info" icon in the right edge of the field next to "Sleep" or "Wake".
- Select "+ Choose Shell Script...", or "Paste" if you copied the script from the Finder.
- Alternatively, you can drag the script file into the file well next to the "Sleep Script" or "Wake Script" heading.