tunnelblick icon Tunnelblick free software for OpenVPN on macOS We need translators for several languages…

Highlighted Articles
  News
  Installing Tunnelblick
  Uninstalling Tunnelblick
  Setting up Configurations
  Using Tunnelblick
  Getting VPN Service
  Common Problems
  Configuring OpenVPN
  Release Notes
  Thanks
  FAQ

Discussion Group
  Read Before You Post

AppleScript Support

On This Page
    Controlling Tunnelblick with AppleScript
    Controlling Tunnelblick from the Command Line
    AppleScript Dictionary
    Examples


Controlling Tunnelblick with AppleScript

This document is about making Tunnelblick do things via scripting. Tunnelblick itself also uses scripts; see Using Scripts.

AppleScripts may connect, disconnect, or list Tunnelblick configurations.

Please note that the verbs only initiate actions. The "connect" verb, for example, is the equivalent of clicking the "Connect" button. It returns immediately after starting an attempt to connect using a particular configuration and does not indicate the connection has been accomplished successfully.

For an example of using Tunnelblick's AppleScript support to solve a particular problem, see this discussion.


Controlling Tunnelblick from the Command Line

You can invoke AppleScript from the command line to control Tunnelblick. You can connect, disconnect, and list configurations.

One way is to store the AppleScript in a file and then invoke it with

   osascript name-of-file

Another way is to include the AppleScript commands in the command line with, for example,

   osascript -e "tell application \"/Applications/Tunnelblick.app\"" -e "connect \"configuration-name\"" -e "end tell"

replacing configuration-name with the name of your configuration.


AppleScript Dictionary

To display the AppleScript commands that are supported by Tunnelblick (or any application), open /Utilities/Script Editor, then click the "File", then "Open Dictionary", and select the application.


Examples

tell application "Tunnelblick"

get configurations
-> {configuration "Work", configuration "Work-Development", configuration "Home", configuration "Test"}

disconnect all
-> 0

connect "Work-Development"
-> true

disconnect (get name of second configuration)
get name of configuration 2
-> "Work-Development"
disconnect "Work-Development"
-> true

connect (get name of first configuration where state = "EXITING")
get name of configuration 1 whose state = "EXITING"
-> "Work"
connect "Work"
-> true

disconnect all except when computer starts
-> 1

get state of second configuration
-> "EXITING"

get state of first configuration where name = "Work"
-> "EXITING"

get name of configurations
-> {"Work", "Work-Development", "Home", "Test"}

get state of configurations
-> {"EXITING", "EXITING", "EXITING", "EXITING"}

get autoconnect of configurations
-> {"NO", "NO", "NO", "NO"}

save username "john.bull" for "Work"
-> 1

save password "password123" for "Work"
-> 1

save passphrase "passphrase123" for "Work"
-> 1

delete all credentials for "Work"
-> 1

end tell