Last active
May 14, 2021 16:53
-
-
Save shubhamgupta0122/012754889af30fa095890d9621047ec0 to your computer and use it in GitHub Desktop.
applescript to toggle vpn via tunnelblick
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set toggle to %TOGGLE% | |
set conf_name to "%NAME%" | |
set conf_user to "%USER%" | |
set conf_pass to "%PASS%" | |
set conf_index to -1 | |
if application "Tunnelblick" is running then | |
else | |
tell application "Tunnelblick" to activate | |
end if | |
tell application "Tunnelblick" | |
-- finding index of configuration in Tunnelblick (applescript sucks) | |
set all_conf_name to (get name of configurations) | |
repeat with i from 1 to length of all_conf_name | |
set curr_conf to item i of all_conf_name | |
if curr_conf is conf_name then | |
set conf_index to i | |
end if | |
end repeat | |
if conf_index is -1 then | |
return "configuration not found" | |
else | |
if toggle | |
delete all credentials for conf_name | |
save username conf_user for conf_name | |
if (state of configuration conf_index) is "EXITING" then | |
save password conf_pass for conf_name | |
connect conf_name | |
return "CONNECTING" | |
else if (state of configuration conf_index) is "CONNECTED" then | |
disconnect conf_name | |
end if | |
end if | |
return state of configuration conf_index | |
end if | |
end tell |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment