VPN Monitor Blog

VPN Monitor Blog

First version ready!

VPN Monitor ScripterPosted by VPN Monitor Sat, August 29, 2015 23:31:44
VPN Monitor Scripter was released today smiley

Download your free copy here (version 1.0).

You probably need to assign the correct "rights" to the App after you unzip it, in order to be able to start the App. Open terminal and use the following command:

chmod +x /Applications/VPN Monitor Scripter.app/Contents/MacOS/VPN Monitor Scripter

VPN Monitor Scripter

What is it?

VPN Monitor Scripter executes an user editable AppleScript when VPN Monitor detects a change in it's VPN connection. This could be when a VPN connection drops, or when a new VPN connection is established.

Why is this interesting?

When your VPN connection is down for an extended period (the VPN server might be unreachable) some users would like to take specific actions. These actions could be to block internet access for certain Apps, send an email, stop torrent transfers, etc.

Why is this not included with VPN Monitor?

Apps in the Appstore are restricted in functionality (for security reasons), one of these restrictions is that the use of AppleScript is not possible.

How do I use it?

Download and start the App and select the menu option "Edit AppleScript":


This will open the AppleScript named "Scripter.applescript" from inside the App's bundle.


Edit this script to your liking and don't forget to compile it and place the compiled script in the same location in the bundle. Select the VPN Monitor Scripter App and "right click" to open the menu, select the option "Show Package Contents":


This will show you the files inside the App. Open the directory "Resources" and copy your compiled AppleScript here, replacing the original script.


What does the supplied AppleScript do?

The standard script will show a system notification when the App starts, providing details of the current status of the VPN connection.

When the connection is lost the option "Stop All Transfers" from the App "BitTorrent" is selected through the Apps menu system. If you do not have BitTorrent installed, a window will open asking you where the App is. Just ignore it, this is an example after all.

When the connection is available again the option "Start All Transfers" from the App "BitTorrent" is selected. BTW: You actually know which VPN Service is connected, so your AppleScript could take specific actions depending on the VPN Service.

This example shows how easy and how powerful AppleScript is (and the reason AppleScript Apps are not allowed in the AppStore).

What are the drawbacks?

The main drawback is that you have another icon sitting in your status bar. However it does provide you with the reassurance that VPN Monitor Scripter is operational (it blinks every time it checks the status of VPN Monitor).

VPN Monitor Scripter is "polling" the status of VPN Monitor at a regular interval. Therefore it is not real-time like VPN Monitor.

Running VPN Monitor Scripter at a very fast interval is not recommended due to the polling nature, it might use too much of your system resources. In any case the speed of a VPN reconnect is usually so quick that running an AppleScript for a disconnect and connect status change is not worth the effort. It's main purpose is to act during a prolonged downtime of your VPN.

The original AppleScript example code to start and stop BitTorrent transfers:

# Example for VPN Monitor Scripter v. 1.2

#

# vpn_status : is called upon connection change

# scripter_start : is called once upon startup of app

# connection_status : "Connected" or Disconnected"

# connected_service : the name of the VPN Service

on vpn_status(connection_status, connected_service)

set t to (time string of (current date))

if connection_status is equal to "Connected" then

display notification "VPN is connected to " & connected_service & ". Resuming Torrent transfers. Time: " & t with title "VPN Monitor Scripter"

try

# BitTorrent

if application "BitTorrent" is running then

tell application "System Events" to tell process "BitTorrent"

tell menu bar item "BitTorrent" of menu bar 1

click

click menu item "Start All Transfers" of menu 1

end tell

end tell

end if

end try

else

display notification "VPN not connected. Stopping Torrent transfers. Time: " & t with title "VPN Monitor Scripter"

try

# BitTorrent

if application "BitTorrent" is running then

tell application "System Events" to tell process "BitTorrent"

tell menu bar item "BitTorrent" of menu bar 1

click

click menu item "Stop All Transfers" of menu 1

end tell

end tell

end if

end try

end if

end vpn_status

# Called once during App start

on scripter_start(connection_status, connected_service)

set t to (time string of (current date))

display notification "App started! " & connection_status & ". VPN: " & connected_service & ". Time: " & t with title "VPN Monitor Scripter"

end scripter_start






  • Comments(0)//blog.vpnmonitor.eu/#post8