Jump to content

Trying to write a script to check VPN status and run shortcut but I failed.


Recommended Posts

So, what I want:


I need the script to simultaneously check the status of four VPNs and if at least one is connected, it would do nothing, but if all are disabled, it would launch the shortcut. But now the script checks the state of VPNs one by one, and it launches the shortcut over and over again. Can you please help me?


Screenshot (Alfred): https://ibb.co/Kj0F3cp


My script:


on run argv
set VPN1 to (system attribute "vpn\_to\_toggle1")

set VPN2 to (system attribute "vpn\_to\_toggle2")

set VPN3 to (system attribute "vpn\_to\_toggle3")

set VPN4 to (system attribute "vpn\_to\_toggle4")

tell application "Tunnelblick"

    set status to get state of first configuration where name = VPN1

    if (status = "CONNECTED") then

    else

        tell application "Shortcuts" to run the shortcut named "Random"

    end if
end tell
tell application "Tunnelblick"

    set status to get state of first configuration where name = VPN2

    if (status = "CONNECTED") then

    else

        tell application "Shortcuts" to run the shortcut named "Random"

    end if
end tell
tell application "Tunnelblick"

    set status to get state of first configuration where name = VPN3

    if (status = "CONNECTED") then

    else

        tell application "Shortcuts" to run the shortcut named "Random"

    end if
end tell
tell application "Tunnelblick"

    set status to get state of first configuration where name = VPN4

    if (status = "CONNECTED") then

    else

        tell application "Shortcuts" to run the shortcut named "Random"

    end if
end tell
end run

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...