Activating the VPN menu item in Mavericks

I am trying to use KM to activate my VPN connection and having trouble coming up with the best way to invoke the log in dialog. I can have KM click on the menu bar item, however if other menu items are activated or removed, the click of course goes to the wrong applet. I cannot locate the process in the process list that could be activated. Any thoughts?

Thanks,
Keith

You might be able to start your VPN by opening a URL or using a shell or AppleScript command.

Selecting status menu items is difficult primarily because there is no easy way of specifying them - they don’t have names so its hard to identify them.

You can use a Click at Found Image, although even that can be difficult as they often animate or change icons based on various states. If the icon does not animate or change state (or has a known state when you want to select from it), then this can be a good solution, followed by Insert Text by Typing “Menu Name%Return%”

To click relative to an image, you use the Mouse Click action, configure it to be relative to a found image, and take a screenshot of the desired area of the screen using Command-Control-Shift-4, and paste it into the image well on the action. The image has to be unique (which includes not being visible in the action if the image is small enough not to be shrunk in the image well) otherwise Keyboard Maestro will not know where to click. The Display option in the action will allow you to see where Keyboard Maestro is matching.

I have looked into it on multiple occasions, and will no doubt look in to it again, but its a difficult problem.

Is there a way in KM or Applescript to see that a VPN is connected?

I would guess the shell command ifconfig -a might give enough information to determine if the VPN is connected.

@Keith, Did you know that you can manually reorder Apple menubar items? Hold ⌘ and drag the VPN icon to place it where you wish. Though this may not be ideal, you could put it in a position you know will be reliable, such as before or after the time.

See the Applescripts I’ve posted over on Github for activating/deactivating a VPN. They should be able to help you out.

1 Like

Any more info on determining if the VPN is active. I’m using Viscosity and I’ve written the AppleScripts to Connect or Disconnect my VPN. I’d like to have that single Hot Key Trigger that either connects the VPN if I’m disconnected or Disconnects the VPN if I’m currently connected. (The behavior would be similar to the show/hide application action) I’m trying to find a way to determine if the VPN is active. Any thoughts?

Thanks

Actually I did this in a kluged way.
I used KM to test for the color of the Viscosity icon in the menu bar. The icon is red when disconnected. So, If it’s red, disconnected, then run the Connect Applescript, if it’s not red then run the Disconnect Applescript.

Hey Patrick,

Then you should be able to use Viscosity to check the connection status.

tell application "Viscosity"
  set activeConnections to connections
  if activeConnections = {} then
    # NOT CONNECTED
  else
    # CONNECTED
  end if
end tell

* I don’t use the app, so this code is not tested (but it conforms to Viscosity’s AppleScript dictionary).

More references:


-Chris