Skip to content
Get connection state by connection name (AppleScript)
Got a problem with Viscosity or need help? Ask here!
this works:
Am I missing something, or can the status of a connection really not be checked by name, even in 1.9?
Code: Select all
this does not ("Script Error: Can’t get state of "PIA-USWest"."):
tell application "Viscosity"
set connectionName to "PIA-USWest"
set connectionState to state of first connection
if connectionState is "Connected" then
disconnect connectionName
else
connect connectionName
end if
end tell
Code: Select all
nor does this ("Script Error: Viscosity got an error: Invalid key form."):
set connectionName to "PIA-USWest"
set connectionState to state of connectionName
Code: Select all
More frustratingly, "the first connection" is actually "PIA-USChicago"; I have no idea why, since it's nowhere near the top of the list. Are there any plans or any way to get the status of a connection by name? This is driving me a little nuts. adding + removing VPN connections and reordering the list results in "the first connection" not being what I would expect at all, and since the status of a connection can't be checked by name, I end up having to write all kinds of crazy nested if/else compare loops. set connectionName to "PIA-USWest"
set connectionState to state of connection connectionName
Am I missing something, or can the status of a connection really not be checked by name, even in 1.9?
Hi aktariel,
As a rule we don't offer support for user-developed AppleScripts (as the time requirements can quickly get out of hand), but as this is a straightforward one:
Replace My Connection with your connection's name. Happy scripting!
Cheers,
James
As a rule we don't offer support for user-developed AppleScripts (as the time requirements can quickly get out of hand), but as this is a straightforward one:
Code: Select all
tell application "Viscosity"
get state of first connection whose name is "My Connection"
end tell
Replace My Connection with your connection's name. Happy scripting!
Cheers,
James
Web: https://www.sparklabs.com
Support: https://www.sparklabs.com/support
Twitter: https://twitter.com/sparklabs
Support: https://www.sparklabs.com/support
Twitter: https://twitter.com/sparklabs
2 posts
Page 1 of 1