Problems with Automating Connection to Wireless Network and VPN

I use a laptop which I take back and forth from the office on a daily basis. At the office I need to be connected to a VPN, and while at home I would like it to be disconnected. Since we use openVPN I bought a copy of Viscosity since it is easily scriptable with AppleScript. A few minutes later I had two scripts, one that would connect to the VPN and the other that would disconnect.

Now the issue, I have tried multiple ways to get the script to automatically fire but nothing seems to work. I used the trigger action on wake and on login. No luck. I also tried the when connected to wireless network and added my office wireless. Nothing works.

So, what am I doing wrong? Is it too much to expect to able to automate connecting and disconnecting from the VPN? This is the second time I have attempted to automate a process with KM only to fail (the first was to have it login when a specific dialog popped up, I have completely given up on that one…)

It would be much easier for us to help you if you would post your existing macro.
See

Keyboard Maestro “Connect Viscosity at Medtronic” Macro

Connect Viscosity at Medtronic.kmmacros (2.5 KB)

Keyboard Maestro “Disconnect Viscosity from Medtronic” Macro

Disconnect Viscosity from Medtronic.kmmacros (2.5 KB)

I uploaded both macros below. Thanks for any assistance you can provide.

-odin

What doesn’t work? The macro is not triggered or the script does not produce the desired effect?

Add a “debug” action, for example a simple Display Text action. So you see if or when the macro triggers.

A note on the triggers:

These are OR triggers. That is, the macro will trigger at every login and every time “mdtmobile” gets connected. The network trigger does not check the connection status, it triggers when the connection gets established.

In case you want to test for the network status, add a condition, for example an If Then Else action:

This way the script will run when…

  • “mdtmobile” gets connected
  • you login and “mdtmobile” is currently connected

The actual script works perfectly, it is the triggering that is failing. It never fires. I have tried several iterations including using the conditions exactly as outlined above. I am at a loss…

Whenever a macro does not fire when expected, the troubleshooting process is the same (as described on the wiki Troubleshooting page).

Here is what to do:

  • Ensure the Keyboard Maestro Engine is running - the Keyboard Maestro status menu should show in the menu bar on the right hand side (unless you’ve turned it off).
  • Ensure you have accessibility enabled (click on the status menu and Keyboard Maestro will tell you if there is a problem).
  • Ensure the Macro Group is enabled, and is active in the application in question.
  • Ensure the macro is enabled.
  • Ensure the macro actions are enabled.
  • Add a status menu trigger, and verify that the macro is active by checking for its name in the Keyboard Maestro status menu.
  • Add a Display Text action to the macro to verify that the macro is firing.
  • Choose Start Debugging from the Status Menu, ensure Pause New Macros is turned on, and trigger the macro. Step through the actions to see where it is going wrong.

Basically, you have to discover if the macro is active, if the trigger is firing, or if the actions are failing.

Also, if a script is failing for any reason, it would be wise to turn on the “display results” option. I know you said the script works, but perhaps the script fails sometimes for some unknown reason.

Also, some applications will ignore AppleScript requests when they are launched. So it is possible the script works while Viscosity is running and fails when it is not.

You have tried it with a Display Text action as explained above, yes?

Is the text window ever displayed after login or after connecting/disconnecting the network? (To be on the sure side add a 2s pause before the Display Text action.)

I'd suggest using only one macro, but with a IF/THEN Action:

##Macro Library   [LOGIN] Set Network Connection on Log In [Example]


####DOWNLOAD:
<a class="attachment" href="/uploads/default/original/2X/d/d3f9f80b9d74f2ce52efc08b6ef6a270f600764f.kmmacros">[LOGIN] Set Network Connection on Log In [Example].kmmacros</a> (5.1 KB)

---

###ReleaseNotes

Change/Add KM Actions in the IF block as needed.

This macro will trigger every time you login.  Then it will test your connection to a wireless network.

---

<img src="/uploads/default/original/2X/c/c86d6fad227ec5ca749bf1650e36dce7904b0fcc.png" width="680" height="770">

@odin, I hope you don’t mind that I have changed the Title of your Topic:
FROM: Automating Frustration
TO: Problems with Automating Connection to Wireless Network and VPN

I think this better reflects the content of your issue, and will help other users to better find the topic.

Hopefully, we can relieve your frustration soon. :wink:

I added a one minute pause after wake/login and that fixed it. Apparently it was a timing issue. Thanks to everyone for your assistance. :slight_smile: