-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsetup
executable file
·67 lines (63 loc) · 1.89 KB
/
setup
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
59
60
61
62
63
64
65
66
67
#!/bin/bash
PLIST_DIR=$HOME/Library/LaunchAgents
realpath() {
[[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}"
}
DIR=$(dirname $(realpath "$0"))
case "$1" in
install)
cat > $PLIST_DIR/LocationChanger.plist << EOT
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>locationchanger</string>
<key>ProgramArguments</key>
<array>
<string>$DIR/location-changer</string>
</array>
<key>WatchPaths</key>
<array>
<string>/Library/Preferences/SystemConfiguration/com.apple.airport.preferences.plist</string>
</array>
</dict>
</plist>
EOT
cat > $PLIST_DIR/LocationChanged.plist << EOT
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>locationchanged</string>
<key>OnDemand</key>
<true/>
<key>ProgramArguments</key>
<array>
<string>$DIR/location-changed</string>
</array>
<key>WatchPaths</key>
<array>
<string>/Library/Preferences/SystemConfiguration/preferences.plist</string>
</array>
</dict>
</plist>
EOT
# Avoid overwriting preferences
[ ! -d ~/.locations ] && cp -R .locations ~/
launchctl unload ~/Library/LaunchAgents/LocationChanger.plist
launchctl unload ~/Library/LaunchAgents/LocationChanged.plist
launchctl load ~/Library/LaunchAgents/LocationChanger.plist
launchctl load ~/Library/LaunchAgents/LocationChanged.plist
;;
uninstall)
launchctl unload ~/Library/LaunchAgents/LocationChanger.plist
launchctl unload ~/Library/LaunchAgents/LocationChanged.plist
rm ~/Library/LaunchAgents/LocationChanger.plist
rm ~/Library/LaunchAgents/LocationChanged.plist
;;
*)
echo "Usage: $0 [install | uninstall]"
;;
esac