Last active
October 10, 2015 17:34
-
-
Save reitermarkus/1cbe18fec5172353ea25 to your computer and use it in GitHub Desktop.
OS X LaunchDaemon to automatically wake or boot your Mac every 15 minutes in case of a power failure – using pmset.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
launchd_name='com.apple.AutoWake' | |
launchd_plist=/Library/LaunchDaemons/"$launchd_name".plist | |
sudo dd of=$launchd_plist <<'EOF' &>/dev/null | |
<plist version="1.0"><dict><key>ProgramArguments</key><array><string>/bin/bash</string><string>-c</string><string>weekdays=MTWRFSU; eventtype=wakeorpoweron; sudo pmset repeat $eventtype $weekdays 05:30:00; for i in {0..23}; do seconds=`date +%s`; seconds=$(($seconds+(3600*$i))); hour=`date -r $seconds +'%m/%d/%y %H'`; minute=`date -r $seconds +%M`; for min in 00 15 30 45; do if [[ $i != 0 ]] || ([[ $i == 0 ]] && [[ $minute -lt $min ]]); then if ! sudo pmset -g sched | grep $eventtype | grep -q "$hour:$min:00"; then sudo pmset schedule $eventtype "$hour:$min:00"; fi; fi; done; done</string></array></dict></plist> | |
EOF | |
sudo plutil -convert xml1 $launchd_plist | |
sudo defaults write $launchd_plist Label -string "$launchd_name" | |
sudo defaults write $launchd_plist RunAtLoad -bool true | |
sudo defaults write $launchd_plist KeepAlive -bool false | |
sudo defaults write $launchd_plist StartInterval -int 300 | |
sudo chmod 644 $launchd_plist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
weekdays=MTWRFSU | |
eventtype=wakeorpoweron | |
sudo pmset repeat $eventtype $weekdays '05:30:00' | |
for i in {0..23}; do | |
seconds=`date +%s` | |
seconds=$(($seconds+(3600*$i))) | |
hour=`date -r $seconds +'%m/%d/%y %H'` | |
minute=`date -r $seconds +%M` | |
for min in 00 15 30 45; do | |
if [[ $i != 0 ]] || ([[ $i == 0 ]] && [[ $minute -lt $min ]]); then | |
if ! sudo pmset -g sched | grep -q "$eventtype at $hour:$min:00 by '$weekdays'"; then | |
sudo pmset schedule $eventtype "$hour:$min:00" $weekdays | |
fi | |
fi | |
done | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
<plist version="1.0"> | |
<dict> | |
<key>Label</key> | |
<string>com.apple.AutoWake</string> | |
<key>KeepAlive</key> | |
<false/> | |
<key>RunAtLoad</key> | |
<true/> | |
<key>StartInterval</key> | |
<integer>300</integer> | |
<key>ProgramArguments</key> | |
<array> | |
<string>/bin/sh</string> | |
<string>-c</string> | |
<string>weekdays=MTWRFSU; eventtype=wakeorpoweron; sudo pmset repeat $eventtype $weekdays '05:30:00'; for i in {0..23}; do seconds=`date +%s`; seconds=$(($seconds+(3600*$i))); hour=`date -r $seconds +'%m/%d/%y %H'`; minute=`date -r $seconds +%M`; for min in 00 15 30 45; do if [[ $i != 0 ]] || ([[ $i == 0 ]] && [[ $minute -lt $min ]]); then if ! sudo pmset -g sched | grep -q "$eventtype at $hour:$min:00 by '$weekdays'"; then sudo pmset schedule $eventtype "$hour:$min:00" $weekdays; fi; fi; done; done</string> | |
</array> | |
</dict> | |
</plist> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Put
com.apple.AutoWake.plist
into/Library/LaunchDaemons/
and run these commands:or