使用brew安装sleepwatcher
brew install sleepwatcher
设置自启动
brew services start sleepwatcher
查看sleepwatcher进程是否启动
ps aux | grep sleepwatcher
可以看到监听了两个脚本文件,分别是.sleep 和 .wakeup,对应睡眠和唤醒。
root 40992 0.0 0.0 4399356 796 s006 S+ 1:41PM 0:00.00 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn sleepwatcher
root 40856 0.0 0.0 4341932 3824 ?? S 1:41PM 0:00.01 /usr/local/sbin/sleepwatcher -V -s ~/.sleep -w ~/.wakeup
创建脚本文件
cd ~
touch .sleep
touch .wakeup
sudo chmod +x .sleep
sudo chmod +x .wakeup
.sleep中写入代码
/usr/bin/sntp -sS time.apple.com
Done!