Help with new AppleScript support

I noticed that there were some additions to the AppleScript library for Viscosity.

I maintain the Quicksilver plug-in and some features can be added if I could query the state of a connection, but I can’t seem to get it to work. (I know very little about AppleScript.)

When I do something like this:

tell application "Viscosity"
	set someVar to the state of "My Connection"
end tell

The result is:

error “Can’t get state of "My Connection".” number -1728 from «class stat» of "My Connection”

I know the name of the connection is valid because I have no problem with:

tell application "Viscosity”
	disconnect "My Connection"
end tell

Am I doing this right?

Hi Skurfer,

The old connect/disconnect functions reference directly by name, which isn’t a nice way of doing things. We’ve kept them around for backwards compatibility, but also introduced the ability to get a list of all connections (a list of connection objects). You could loop through this list to find the connection you want (and get its name/state, or tell it to connect/disconnect), or do something like so:

tell application "Viscosity"
	set someVar to state of connections where name is equal to "My Connection"
end tell

Cheers,
James

The old connect/disconnect functions reference directly by name, which isn’t a nice way of doing things.

OK, then I should probably start doing this instead of using the name directly, right?

tell application "Viscosity" to connect (connections where name is connName)

Seems to work.

We’ve … introduced the ability to get a list of all connections (a list of connection objects). You could loop through this list to find the connection you want (and get its name/state, or tell it to connect/disconnect), or do something like so:

I started down the path of using AppleScript to index the connections, since that seems like the most reliable way to get them, but then it occurred to me that this only works if Viscosity is running (or if not, it will launch the application). Quicksilver should be able to index the connections without the app running, so I’m going to stick with the current method of scanning config files in ~/Library/Application Support/Viscosity/OpenVPN.

Is that a bad idea? I mean, do you anticipate any changes to the directory layout or config file metadata comments in the foreseeable future?

OK, then I should probably start doing this instead of using the name directly, right?

Ideally, yes.

Is that a bad idea? I mean, do you anticipate any changes to the directory layout or config file metadata comments in the foreseeable future?

It’s not pretty, but if it works, it works! :slight_smile: No changes are currently planned to the way connections are stored.

Cheers,
James

Hi James,

how will i get the mentioned list of all connections?

Thanks!

Hi markco3000,

Please see the following support article for how to control Viscosity using AppleScript:
http://www.sparklabs.com/support/controlling_viscosity_with_app/

If, for example, you wanted to output a list of connection names:

tell application "Viscosity"
	repeat with conn in connections
		name of conn
	end repeat
end tell

Cheers,
James

Thanks a lot James,

maybe i write some more about my intention. I try to integrate Yubikey in our VPN. To do so, i need to alter the keychain objects from viscosity with the one time password before starting the viscosity connection with a “before connect” script.

As you store the keychain objects by the “internal” number of the connection, i would need that number too. Is there a way to get this connection number?

Example:

name: my VPN connection
keychain item: Viscosity/4/ovpn

I

Hi markco3000,

I’m afraid you’d need to examine the file system to find out the raw connection IDs: they’re not available through AppleScript.

That said, for things like YubiKey we recommend using Viscosity and OpenVPN’s static challenge support which is built especially for one time passwords (instead of using the Username/Password dialog). Information about static challenge support can be found in the following post:
https://www.sparklabs.com/forum/t/otp-box-in-login-prompt/696/2

Cheers,
James