Connection Names and AppleScript

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

netboy2020

User avatar
Posts: 2
Joined: Sun Mar 20, 2016 7:39 pm

Post by netboy2020 » Tue May 03, 2016 3:57 am
I was curious if it's at all possible to query a connection state by name? The numbers "first, second, third" don't match the folder numbers and I'm confused where they came from. Or, is there a way to identify the connection number without running AppleScript, as documented by SparkLabs?

I imagined the following, and tried a few other things, but nothing worked...

Instead of
Code: Select all
if the state of the last connection is "Connected" then
Something like
Code: Select all
if the state of the connection name "VyprLAX" is "Connected" then
It would just be simpler and less confusing, but I understand it may not be built in this way.

Thanks!


Incidentally, to get the connection numbers I ran the below, as documented at support/kb/article/controlling-viscosity-with-applescript-mac/
Code: Select all
tell application "Viscosity"
set connectionName to name of the first connection
display dialog connectionName
end tell
[/size]

netboy2020

User avatar
Posts: 2
Joined: Sun Mar 20, 2016 7:39 pm

Post by netboy2020 » Tue May 03, 2016 4:09 am
Okay, well, it seems my topic is completely wrong now and this is a combo of being about the connection names/applescript and now playing a sound until a connection is made.

What I attempted did not work at all. I am trying to run a repeat until the connection is made. It seems to be stuck in the loop and not proceed with the connection. Viscosity stalls at "Running on Mac OS X 10.11.4" and doesn't reach "Checking reachability status of connection..."

My script works if I run it from Script Editor and try to connect. My "Before Connect" script, which I was going to then build off for the connection, looks like the below. Is the tell application Viscosity causing this?

So, I saved it as an App and had the App launch in the Before Connect script, which worked. But, this seems cumbersome if there's a better way to do it.

Full Script Contents:
Code: Select all
set x to true
repeat while x is true
	tell application "Viscosity"
		if the state of the last connection is "Connected" then
			set x to false
		else
			do shell script "afplay '/System/Library/Sounds/Morse.aiff'"
		end if
	end tell
end repeat

James

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

Post by James » Tue May 03, 2016 9:58 am
Hi netboy2020,

Before-Connect scripts run before a connection attempt is started, and Viscosity will wait for them to complete before initiating the connection attempt (as they're typically used to initiate actions necessary for the connection to succeed). The script posted above will loop endlessly as the connection will never reach a "Connected" state.

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