Viscosity. OpenVPN client. For Mac.  
 
 

Help with new AppleScript support

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

Help with new AppleScript support

Postby Skurfer » Sat Jul 24, 2010 12:31 am

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?
Skurfer
 
Posts: 3
Joined: Wed Jan 27, 2010 4:05 pm

Re: Help with new AppleScript support

Postby James » Sat Jul 24, 2010 3: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
User avatar
James
 
Posts: 356
Joined: Thu Sep 04, 2008 10:27 pm

Re: Help with new AppleScript support

Postby Skurfer » Tue Aug 03, 2010 12:10 am

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?
Skurfer
 
Posts: 3
Joined: Wed Jan 27, 2010 4:05 pm

Re: Help with new AppleScript support

Postby James » Tue Aug 03, 2010 12:44 pm

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
User avatar
James
 
Posts: 356
Joined: Thu Sep 04, 2008 10:27 pm


Return to Viscosity Support

Who is online

Users browsing this forum: No registered users and 1 guest



 
 
 
 
Navigate

Home
Applications
Blog
About
Support
  Support

Support Home
Documentation
Knowledge Base
Forum
  Community

Blog
Forum
Twitter
Viscosity
Viscosity Server


 
 
SparkLabs Copyright © SparkLabs. All Rights Reserved.