-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_auto_sync.sh
More file actions
executable file
·58 lines (48 loc) · 1.46 KB
/
Copy pathsetup_auto_sync.sh
File metadata and controls
executable file
·58 lines (48 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/bash
# 设置 macOS LaunchAgent,每天自动同步 token 数据到 GitHub。
# 用法:bash setup_auto_sync.sh
set -e
PLIST_DIR="$HOME/Library/LaunchAgents"
PLIST_FILE="$PLIST_DIR/com.token-tracker.sync.plist"
PYTHON=$(which python3)
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
LOG_DIR="$SCRIPT_DIR/logs"
mkdir -p "$PLIST_DIR" "$LOG_DIR"
cat > "$PLIST_FILE" <<EOF
<?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.token-tracker.sync</string>
<key>ProgramArguments</key>
<array>
<string>$PYTHON</string>
<string>$SCRIPT_DIR/sync.py</string>
</array>
<!-- 每天 12:00 运行 -->
<key>StartCalendarInterval</key>
<dict>
<key>Hour</key> <integer>12</integer>
<key>Minute</key> <integer>0</integer>
</dict>
<key>StandardOutPath</key>
<string>$LOG_DIR/sync.log</string>
<key>StandardErrorPath</key>
<string>$LOG_DIR/sync.err</string>
<!-- 登录后才运行 -->
<key>RunAtLoad</key>
<false/>
</dict>
</plist>
EOF
# 加载(如已存在则先卸载)
launchctl unload "$PLIST_FILE" 2>/dev/null || true
launchctl load "$PLIST_FILE"
echo "✓ LaunchAgent 已安装:每天 12:00 自动同步"
echo " 配置文件:$PLIST_FILE"
echo " 日志目录:$LOG_DIR"
echo ""
echo "手动立即同步:python3 $SCRIPT_DIR/sync.py"
echo "卸载自动同步:launchctl unload $PLIST_FILE"