How to Automatically Schedule Syncing with launchctl on rime macOS

First, create a sh script to achieve Rime synchronization via the command line. I placed it at /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 "Synchronizing Rime input method..."

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

Then, create a plist file (for example, mine is called com.whitewatercn.rime.autosync) in a specific folder (see below) to periodically execute the above script

<?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> <!-- absolute path to your sh -->
    </array>
    <key>StartCalendarInterval</key> <!-- timer, see below for details -->
        <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> <!-- execution log path, can be anywhere -->
    <key>StandardErrorPath</key>
    <string>/Users/ww/Scripts/rime_auto_sync.err</string> <!-- error log path, can be anywhere -->
</dict>
</plist>

How to use the timer

The StartCalendarInterval tag means execution at a specified time

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)

Where can the plist be placed?

In the example above, the .plist descriptor file is placed in the /Users/ww/Library/LaunchAgents/ directory. Besides this directory, it can also exist in other locations:

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

References

1 Like