share-image
ESC

mac 定时执行任务

1.进入目录

cd ~/Library/LaunchAgents/

创建一个文件,内容如下

➜  LaunchAgents cat com.autolockscreen.scheduledJobs.plist
<?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.autolockscreen.scheduledJobs</string>
<key>ProgramArguments</key>
<array>
<string>pmset</string>
<string>sleepnow</string>
</array>
<key>StartCalendarInterval</key>
<array>
<dict>
<key>Hour</key>
<integer>11</integer>
<key>Minute</key>
<integer>30</integer>
</dict>
<dict>
<key>Hour</key>
<integer>17</integer>
<key>Minute</key>
<integer>30</integer>
</dict>
</array>
</dict>
</plist>

这个程序表示 11点30 和17点30 执行休眠命令 pmset sleepnow。
设置为开机启动

launchctl load com.autolockscreen.scheduledJobs.plist

立即启动

launchctl start com.autolockscreen.scheduledJobs.plist
文章作者:阿文
文章链接: https://www.awen.me/post/31521.html
版权声明:本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 阿文的博客
本文于 2018-08-14 发布,已超过半年(2724天),请注意甄别内容是否已过期。