Repository navigation
Expand file tree
/
Copy pathexample.sh
More file actions
executable file
·90 lines (70 loc) · 1.63 KB
/
Copy pathexample.sh
File metadata and controls
executable file
·90 lines (70 loc) · 1.63 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/bin/sh
# author: JeffMa
# created: 2016.11.17
# launchd-with-networkchange
# proxifier
proxifier_quit()
{
ps -ef | grep Proxifier | awk '{print $2}' | xargs kill
}
# WORK MOD
at_work_mod()
{
# empty dns servers when connect office wifi
/usr/sbin/networksetup -setdnsservers Wi-Fi Empty
# set pac url for work place Wi-Fi
# slient
osascript -e "set Volume 0"
osascript <<EOD
tell application "RTX"
run
end tell
tell application "ShadowsocksX"
quit
end tell
EOD
}
# HOME MOD
at_home_mod()
{
# set my pac url so that i can across the GFW at home.
# /usr/sbin/networksetup -setautoproxyurl Wi-Fi http://example.pac
# run or quit apps
osascript <<EOD
tell application "RTX"
quit
end tell
EOD
}
NAME="$0:t:r"
PPID_NAME=$(ps -cp "$PPID" | fgrep -v 'PID TTY')
case "$PPID_NAME" in
*launchd*)
# delay 15s for Mac's first wakes up.
sleep 15
;;
*)
# These settings are used when the script is not called via `launchd`
;;
esac
# delay
sleep 3
# GET SSID
SSID=$(/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I | awk -F': ' '/ SSID/{print $NF}')
# whether at home or working by detecting SSID.
# Please change the code according to your contexts,
# especially the SSID name.
if [[ $SSID == 'Office-WiF-SSID' ]];then
at_work_mod
SHOW_MOD="Work Mod"
else
at_home_mod
SHOW_MOD="Home Mod"
fi
# notification
if [[ $SHOW_MOD != '' ]];then
osascript <<EOD
display notification "Run [ $SHOW_MOD ] with success!" with title "Launchd With Networkchange"
EOD
fi
exit 0