App Support.

We're here to help.



Controlling Viscosity with AppleScript (Mac)

Viscosity provides AppleScript support, allowing VPN connections to be connected, disconnected, or their name and state listed, from AppleScript scripts.

Viscosity Suite

AppleScript Classes

  • connection n : A connection.

    Properties
    name (text, r/o) : The name of the connection.
    state (text, r/o) : The state of the connection.

    Responds To
    connect, disconnect.

AppleScript Commands

  • connect name : the name of the VPN connection to connect
  • disconnect name : the name of the VPN connection to disconnect
  • connectall
  • disconnectall

Examples

Several examples of how you can interact with Viscosity using AppleScript have been included below.

Connect A Connection By Name

tell application "Viscosity" to connect "Home"

Disconnect A Connection By Name

tell application "Viscosity" to disconnect "Home"

Display Name Of The First Connection

tell application "Viscosity"
set connectionName to name of the first connection
display dialog connectionName
end tell

Display State Of The First Connection

tell application "Viscosity"
set connectionState to state of the first connection
display dialog connectionState
end tell

Action Depending On State Of The First Connection

tell application "Viscosity"
if the state of the first connection is "Connected" then ...
end tell

Connect All Connections

tell application "Viscosity" to connectall

Disconnect All Connections

tell application "Viscosity" to disconnectall

Using AppleScript From The Terminal

AppleScript scripts and commands can be used directly from the Terminal using the "osascript" command. For example:

osascript -e 'tell application "Viscosity" to connect "Home"'