我的 Mac mini 全天运行,上面挂着 Parsec 远程控制 APP,需要时我会通过 Parsec 连上去使用。然而 Parsec 长时间运行后,偶尔会崩溃,搞得我需要跑到 Mac 旁边手动点重启才能重新连上。有没有办法能让它崩溃以后自动重启呢?
先打开自带的“脚本编辑器”,写一个 AppleScript 脚本,判断 Parsec 是否正在运行,如果没有运行,就启动 Parsec。
if application "Parsec" is not running then
tell application "Parsec" to activate
end if
将脚本保存到合适的位置,我这里是 /Users/mae/workspace/applescript/autorun.scpt
,再写一个任务,每隔 233 秒执行一次上面的脚本。
<?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.imaegoo.autorun.scpt</string>
<key>ProgramArguments</key>
<array>
<string>osascript</string>
<string>/Users/mae/workspace/applescript/autorun.scpt</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>StartInterval</key>
<integer>233</integer>
</dict>
</plist>
保存到 /Users/mae/Library/LaunchAgents/com.imaegoo.autorun.scpt.plist
,然后执行命令启用这个定时任务。
launchctl load -w /Users/mae/Library/LaunchAgents/com.imaegoo.autorun.scpt.plist
以后再也不怕我的 Mac mini 失联了!
评论列表 (0条):
加载更多评论 Loading...