A use for Tunnelblick's AppleScript support

4,471 views
Skip to first unread message

cmac

unread,
Jun 27, 2011, 10:38:56 AM6/27/11
to tunnelbli...@googlegroups.com
I have a particular use of Applescript and Automator with Tunnelblick, I'm posting it here in case anyone else is interested in the idea.

In February Applescript support got added to Tunnelblick 3.2.  It's just what I was waiting for, it gave me an idea to enhance an existing Automator workflow I have.

Here's how I use it:
I work mostly remotely from my companies head office and my development team.  I get frequently get emails and documents from colleagues that refer to DI codes for our JIRA DB, they take the form "PRODUCT-1234".  The DB is behind the firewall so I need to VPN in first.

Previously in order to view them I had to:
1. Connect to the VPN (I don't like leaving it up all the time)
2. Hit a browser bookmark to get to our JIRA
3. Retype the DI code or copy & paste from the email and <Return> to go there.

I got sick of that so I eventually set up an Automator Service (called 'JIRA Link')  that allows me to:
1. Highlight the DI code
2. 'right-click > Services >  JIRA Link'
3. which passes the DI code to Automator which appends it to to a pre-formatted URL and then opens my Browser to that location.

However, I would frequently then discover that I was not connected to VPN before doing it and would get a '404 Not Found' error.

After installing 3.2Beta, I added the following AppleScript to the start of my Automator workflow:

tell application "Tunnelblick"
connect "Company_VPN"
get state of first configuration where name = "Company_VPN"
repeat until result = "CONNECTED"
delay 1
get state of first configuration where name = "Company_VPN"
end repeat
end tell

This checks to see if the VPN is up first, and connects if it is not.  The 'repeat' is needed as otherwise the service would go straight to trying to open the URL and fail since the VPN wasn't up yet, this gives it a short delay before retrying.


Hopefully it sparks an AppleScript/Automator idea for someone else.

Thanks to Jonathan for the AppleScript support, suggestions and fixing my malformed conf file.

Cheers,
Cameron

jkbull...gmail.com

unread,
Jun 27, 2011, 10:47:15 AM6/27/11
to tunnelbli...@googlegroups.com
Thanks for posting this -- I think the use of "repeat" will help other people, too.

I have put a link to your post on the AppleScript Support page.

cmac

unread,
Feb 19, 2013, 10:50:58 AM2/19/13
to tunnelbli...@googlegroups.com
Hi Ryan,

No worries, I'm glad someone else was able to make use of this.

Cameron

On Monday, February 18, 2013 11:12:45 AM UTC-5, Ryan Eff wrote:
Cameron,

Thank you for your post. Your script helped me figure out applescript a little bit. Using yours as a starting point I have crafted an applescript of my own that stops uTorrent in the event of vpn disconnection, reconnects the vpn and restarts uTorrent. I owe you one!

Before: I left my computer downloading movies via uTorrent, and came home to find my vpn disconnected, uTorrent still running, and my IP being sprayed all over the place. 
After: The script below first connects my vpn of choice and opens uTorrent. Then it repeats the following indefinitely: watches the Tunnelblick connection every 1 second. If it is connected, it just keeps checking every second until it detects a disconnect. Upon disconnect, it quits uTorrent, reconnects the vpn connection via tunnelblick, and restarts uTorrent.

tell application "Tunnelblick"

connect "config"

get state of first configuration where name = "config"

repeat until result = "CONNECTED"

delay 1

get state of first configuration where name = "config"

end repeat

if result = "connected" then run application "uTorrent"

end tell

repeat

tell application "Tunnelblick"

get state of configuration 1 whose name = "config"

if result = "connected" then repeat until result = "exiting"

delay 1

get state of configuration 1 whose name = "config"

end repeat

if result = "exiting" then quit application "uTorrent"

tell application "Tunnelblick"

connect "config"

get state of first configuration where name = "config"

repeat until result = "CONNECTED"

delay 1

get state of first configuration where name = "config"

end repeat

run application "uTorrent"

end tell

end tell

end repeat


"config" is replaced with my vpn of choice as it appears in the tunnelblick drop down menu. I was so excited that it worked, I had to share it.


Thanks again cameron, and a big thanks to the developer of tunnelblick!


-Ryan





Qi Luk

unread,
Jan 28, 2017, 12:09:30 AM1/28/17
to tunnelblick-discuss
How to verify that the computer is connected to Internet before letting Tunnelblick to repeatedly reconnect VPN?

Tunnelblick developer

unread,
Jan 28, 2017, 5:43:46 AM1/28/17
to tunnelblick-discuss
Tunnelblick does not have an option to check that you are connected to the Internet.

A search for applescript check internet connectivity on any search engine should provide useful results.

nandud...@phonepe.com

unread,
Jun 5, 2017, 6:28:16 AM6/5/17
to tunnelblick-discuss
Could you please help how I can additionally pass username and oathtool generated otp password for authentication ?

da...@afterbanks.com

unread,
Aug 28, 2019, 9:34:41 AM8/28/19
to tunnelblick-discuss
hank you all for your contributions. That's how I use it.

Usually you only have one connection to a single VPN, so I made this modification by removing the where to make it more universal, as each of my peers has a different connection name.

tell application "Tunnelblick"
  get name of first configuration
  connect result
  repeat until result = "CONNECTED"
    delay 1
    get state of first configuration
  end repeat
end tell

Also, to be able to include it inside our .sh that check other things before connecting to the VPN, I run it this way inside our bash script

osascript -e 'tell application "Tunnelblick"' -e ' get name of first configuration' -e ' connect result' -e ' repeat until result = "CONNECTED"' -e ' delay 1' -e ' get state of first configuration' -e ' end repeat' -e 'end tell'

A efectos de lo dispuesto en la normativa vigente relativa a la protección de datos de carácter personal, MORPHEUS AIOLOS S.L. (Afterbanks.com) le informa que sus datos están incorporados a un fichero automatizado de datos de carácter personal, creado bajo la  responsabilidad de MORPHEUS AIOLOS S.L., con la finalidad de ofrecerle un servicio más personalizado, ágil y eficaz. MORPHEUS AIOLOS S.L. se compromete al cumplimiento de su obligación de secreto de los datos de carácter personal y de su deber de guardarlos, y adoptará las medidas necesarias para evitar su alteración, pérdida, tratamiento o acceso no autorizado, habida cuenta en todo momento del estado de la tecnología. Así mismo, le comunicamos que puede ejercitar los derechos de acceso, rectificación, cancelación y oposición establecidos por la citada normativa mediante petición escrita dirigida a: MORPHEUS AIOLOS S.L., C/ de San Andrés 8, Local, 28004, MADRID, MADRID, Tel. 911 126 709, Email in...@morpheusaiolos.com
El correo electrónico vía Internet no permite asegurar la confidencialidad de los mensajes que se transmiten ni su integridad o correcta recepción. Morpheus Aiolos no asume ninguna responsabilidad por estas circunstancias.
Reply all
Reply to author
Forward
0 new messages