rime macos如何通过launchctl自动定时同步

先创建sh脚本,实现通过命令行执行rime同步,我放在了 /Users/ww/Scripts/rime_auto_sync.sh

#!/bin/bash

# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title rime同步 sync
# @raycast.mode silent

# Optional parameters:
# @raycast.icon 🤖

# Documentation:
# @raycast.author whitewatercn

echo "正在同步 Rime 输入法..."

/Library/Input\ Methods/Squirrel.app/Contents/MacOS/Squirrel --sync

然后在特定文件夹(详见下)创建plist文件(比如我的plist就叫 com.whitewatercn.rime.autosync ),实现定期执行上述脚本

<?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.whitewatercn.rime.autosync</string>
    <key>ProgramArguments</key>
    <array>
        <string>/bin/bash</string>
        <string>/Users/ww/Scripts/rime_auto_sync.sh </string> #你的sh所在绝对路径
    </array>
    <key>StartCalendarInterval</key> #定时器, 具体怎么用详见下
        <dict>
        	<key>Hour</key>
        	<integer>14</integer>
        	<key>Minute</key>
        	<integer>40</integer>
    	</dict>
    <key>RunAtLoad</key>
    <true/>
    <key>StandardOutPath</key>
    <string>/Users/ww/Scripts/rime_auto_sync.log</string> #执行日志所在路径,放哪都行
    <key>StandardErrorPath</key>
    <string>/Users/ww/Scripts/rime_auto_sync.err</string> #报错日志所在路径,放哪都行
</dict>
</plist>

定时器怎么用

StartCalendarInterval 标签代表指定时间点执行

Key Type Values
Month Integer Month of year (1..12, 1 being January)
Day Integer Day of month (1..31)
Weekday Integer Day of week (0..7, 0 and 7 being Sunday)
Hour Integer Hour of day (0..23)
Minute Integer Minute of hour (0..59)

plist可以放在哪里?

上述展示中,.plist 描述文件是存放在 /Users/ww/Library/LaunchAgents/ 目录下,除了这个目录还可以存在其他位置:

Type Location Run on behalf of
User Agents ~/Library/LaunchAgents Currently logged in user
Global Agents /Library/LaunchAgents Currently logged in user
Global Daemons /Library/LaunchDaemons root or the user specified with the key UserName
System Agents /System/Library/LaunchAgents Currently logged in user
System Daemons /System/Library/LaunchDaemons root or the user specified with the key UserName

参考

1 Like