Skip to content

Instantly share code, notes, and snippets.

@shubhamgupta0122
Last active May 14, 2021 16:53
Show Gist options
  • Select an option

  • Save shubhamgupta0122/012754889af30fa095890d9621047ec0 to your computer and use it in GitHub Desktop.

Select an option

Save shubhamgupta0122/012754889af30fa095890d9621047ec0 to your computer and use it in GitHub Desktop.

Revisions

  1. shubhamgupta0122 revised this gist May 14, 2021. 1 changed file with 14 additions and 11 deletions.
    25 changes: 14 additions & 11 deletions tunnelblick_toggle.applescript
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,7 @@
    set conf_name to "my_tunnelblick_vpn_config_name"
    set conf_user to "username"
    set conf_pass to "secret_password"
    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
    @@ -21,14 +22,16 @@ tell application "Tunnelblick"
    if conf_index is -1 then
    return "configuration not found"
    else
    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
    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
  2. shubhamgupta0122 created this gist May 14, 2021.
    36 changes: 36 additions & 0 deletions tunnelblick_toggle.applescript
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    set conf_name to "my_tunnelblick_vpn_config_name"
    set conf_user to "username"
    set conf_pass to "secret_password"
    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
    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

    return state of configuration conf_index
    end if
    end tell