1

The following Script works as expected in Script Editor:

tell application "System Events"
    set nord to menu bar item 1 of menu bar 2 of application process "NordVPN IKE"
    ignoring application responses
        click nord
    end ignoring
end tell
do shell script "killall System\\ Events"
tell application "System Events"
    set nord to menu bar item 1 of menu bar 2 of application process "NordVPN IKE"
    tell menu 1 of nord
        if exists menu item "Disconnect" then
            click menu item "Disconnect"
        else
            click menu item "Connect"
        end if
    end tell
end tell

When I export it to a .app and double click on it to execute, I get the following error:

Can’t get «class menE» 1 of «class mbri» 1 of «class mbar» 2 of «class pcap» "NordVPN IKE" of application "System Events". Invalid index.

System Events got an error: Can’t get menu 1 of menu bar item 1 of menu bar 2 of application process "NordVPN IKE". Invalid index. (-1719)

How can I change the script so it works as a .app?

Thanks

  • Is this under Mojave? If so, I'd assume that it's some sort of "protection" that the OS is using to prevent the (unsigned?) app from accessing System Events, but Script Editor is allowed because it's a signed / known app. (This is one reason I'm sticking with High Sierra for now, Mojave is very aggressive about these sorts of things.) If it's not Mojave, it would be good to know what version of macOS/OS X/Mac OS X it is. – TJ Luoma Nov 1 '18 at 23:01
  • i'm sorry that link doesn't help at all. please remove the banner on the top of my question. i give it every permission it asks for. if you have a way to modify the script or run it so that it works, that would be an acceptable answer. – Walrus the Cat Nov 2 '18 at 5:26
  • Try adding a tell application "NordVPN IKE" to activate line at the beginning of your program. – abc Nov 2 '18 at 17:46
0

You need to do two things in order to get this to run:

First of all you need to make sure System Events itself has permissions in the Accessibility preference pane.

Secondly, you should add a delay after clicking the menu item to give it time to load. That ultimately is what is causing the index error, because the menu hasn't propagated yet and it's trying to access items in it. Change your script to the following:

....
        click nord
    end ignoring
end tell
delay 0.3
do shell script "killall System\\ Events"
....

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .