-
Notifications
You must be signed in to change notification settings - Fork 1
/
install_sync_agent.sh
executable file
·55 lines (44 loc) · 1.19 KB
/
install_sync_agent.sh
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
#!/bin/bash
# shellcheck disable=2002,2154,2181
. lib/env.sh
AGENT_DIR=${HOME}/Library/LaunchAgents
PLIST="${alfred_workflow_bundleid}".plist
AGENT=${AGENT_DIR}/"${PLIST}"
START_INTERVAL=$((SyncTime * 60))
function load() {
launchctl load -F "${AGENT}"
launchctl start "${alfred_workflow_bundleid}"
}
function unload() {
launchctl unload -F "${AGENT}"
}
# Check for changes
cat sync_agent.plist.template \
| sed "s:WORKFLOW:${alfred_preferences}/workflows/${alfred_workflow_uid}:" \
| sed "s:START_INTERVAL:${START_INTERVAL}:" \
| sed "s:BUNDLEID:${alfred_workflow_bundleid}:" \
> "${PLIST}"
cmp -s "${PLIST}" "${AGENT}"
if [ $? != 0 ]; then
# Changes made
# Copy launch agent plist
[ -d "${AGENT_DIR}"/ ] || mkdir -p "${AGENT_DIR}"/
cp -f "${PLIST}" "${AGENT_DIR}"/
# Unload launch agent
unload
# Load launch agent
if [ "${autoSync}" == 1 ]; then
log "Loading ${AGENT} ${alfred_workflow_bundleid}"
load
fi
else
# No changes made
if [ "${autoSync}" == 0 ]; then
log "Unloading ${AGENT}"
unload
else
# Make sure it's running
launchctl list "${alfred_workflow_bundleid}" > /dev/null
if [ $? != 0 ]; then load; fi
fi
fi