net-tools/tray/vpn-toggle.applescript

28 lines
1,021 B
AppleScript
Raw Permalink Normal View History

-- VPN Toggle: detects WireGuard state on plum and flips it.
-- Up if no utun has 10.9.0.3; otherwise down. Notifies result.
set wgConf to "/Users/natalie/.wireguard/wg1.conf"
set wgQuick to "/opt/homebrew/bin/wg-quick"
set isUp to false
try
do shell script "/sbin/ifconfig | /usr/bin/grep -q 'inet 10.9.0.3'"
set isUp to true
end try
if isUp then
try
do shell script (quoted form of wgQuick) & " down " & (quoted form of wgConf) & " 2>&1" with administrator privileges
display notification "WireGuard wg1 is down." with title "VPN Toggle" subtitle "Disconnected"
on error errMsg
display notification errMsg with title "VPN Toggle" subtitle "Failed to disconnect"
end try
else
try
do shell script (quoted form of wgQuick) & " up " & (quoted form of wgConf) & " 2>&1" with administrator privileges
display notification "WireGuard wg1 is up." with title "VPN Toggle" subtitle "Connected"
on error errMsg
display notification errMsg with title "VPN Toggle" subtitle "Failed to connect"
end try
end if