Help with new AppleScript support

Got a problem with Viscosity or need help? Ask here!

Skurfer

Posts: 4
Joined: Wed Jan 27, 2010 4:05 pm

Post by Skurfer » Fri Jul 23, 2010 11:31 pm
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:
Code: Select all
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:
Code: Select all
tell application "Viscosity”
	disconnect "My Connection"
end tell
Am I doing this right?

James

User avatar
Posts: 2313
Joined: Thu Sep 04, 2008 9:27 pm

Post by James » Sat Jul 24, 2010 2:05 am
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:
Code: Select all
tell application "Viscosity"
	set someVar to state of connections where name is equal to "My Connection"
end tell
Cheers,
James
Web: https://www.sparklabs.com
Support: https://www.sparklabs.com/support
Twitter: https://twitter.com/sparklabs

Skurfer

Posts: 4
Joined: Wed Jan 27, 2010 4:05 pm

Post by Skurfer » Mon Aug 02, 2010 11:10 pm
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?
Code: Select all
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?

James

User avatar
Posts: 2313
Joined: Thu Sep 04, 2008 9:27 pm

Post by James » Tue Aug 03, 2010 11:44 am
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! :) No changes are currently planned to the way connections are stored.

Cheers,
James
Web: https://www.sparklabs.com
Support: https://www.sparklabs.com/support
Twitter: https://twitter.com/sparklabs

markco3000

Posts: 2
Joined: Fri May 23, 2014 1:34 am

Post by markco3000 » Fri May 23, 2014 1:40 am
James wrote:
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:
Code: Select all
tell application "Viscosity"
	set someVar to state of connections where name is equal to "My Connection"
end tell
Cheers,
James
Hi James,

how will i get the mentioned list of all connections?

Thanks!

James

User avatar
Posts: 2313
Joined: Thu Sep 04, 2008 9:27 pm

Post by James » Sat May 24, 2014 9:55 am
Hi markco3000,

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

If, for example, you wanted to output a list of connection names:
Code: Select all
tell application "Viscosity"
	repeat with conn in connections
		name of conn
	end repeat
end tell
Cheers,
James
Web: https://www.sparklabs.com
Support: https://www.sparklabs.com/support
Twitter: https://twitter.com/sparklabs

markco3000

Posts: 2
Joined: Fri May 23, 2014 1:34 am

Post by markco3000 » Mon May 26, 2014 6:26 pm
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

James

User avatar
Posts: 2313
Joined: Thu Sep 04, 2008 9:27 pm

Post by James » Tue May 27, 2014 11:49 am
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:
http://www.sparklabs.com/forum/viewtopi ... 3677#p3677

Cheers,
James
Web: https://www.sparklabs.com
Support: https://www.sparklabs.com/support
Twitter: https://twitter.com/sparklabs
8 posts Page 1 of 1