If I don't ignore and kill that I have to wait ~7 seconds between open the menu bar 2 menu and selecting the submenu. I found somebody having a similar problem and his solution was to kill the "waiting". This works when System Events is already running, but not, when not.
So if I remove the ignoring and kill stuff the workflow works, but have a ~7seconds pause before the submenu is selected.
I tried to combine it:
tell application "System Events" to tell process "Pulse Secure"
click menu item "Connect" of menu network of menu item network of menu bar item 1 of menu bar 2
end tell
but so far I couldn't manage it to work:
[ERROR: alfred.workflow.action.applescript] {
NSAppleScriptErrorAppName = "System Events";
NSAppleScriptErrorBriefMessage = "Can\U2019t get menu item \"work network\" of menu bar item 1 of menu bar 2 of process \"Pulse Secure\".";
NSAppleScriptErrorMessage = "System Events got an error: Can\U2019t get menu item \"work network\" of menu bar item 1 of menu bar 2 of process \"Pulse Secure\".";
NSAppleScriptErrorNumber = "-1728";
NSAppleScriptErrorRange = "NSRange: {499, 95}";
}
Thanks so far