mort_the_swift Posted March 31, 2020 Share Posted March 31, 2020 I have an AppleScript that presses the 'Connect to...' button under the menu bar icon of my VPN client. tell application "System Events" if exists process "IVPN" then tell process "IVPN" to tell menu bar item 1 of menu bar 2 ignoring application responses click end ignoring end tell end if end tell do shell script "killall System\\ Events" delay 0.1 tell application "System Events" if exists process "IVPN" then tell process "IVPN" to tell menu bar item 1 of menu bar 2 tell menu 1 if exists (first menu item whose title starts with "Connect to") then click (first menu item whose title starts with "Connect to") else key code 53 end if end tell end tell end if end tell If there is no such button (already connected), then the escape keystroke is sent (to close the menu). Due to the 5s delay after the first click (a known UI scripting behavior), I had to add a workaround that ignores application response on the first click and then kills all instances of 'System Events' via a shell command, and then clicks the actual button. This setup works consistently when launched from the Script Editor. However, in Alfred it just doesn't. There are no errors in the debug console, and, judging by the bell sound, the script always ends up sending the key code 53 (pressing Esc). What exactly could be the problem? Link to comment
vitor Posted March 31, 2020 Share Posted March 31, 2020 Welcome @mort_the_swift, When asking for help with a Workflow, please upload it somewhere (transfer.sh is a fast solution without ads; drop your Workflow in the box in the middle) as we can’t properly help you without access to it. Debugging can already be hard with access to the code, and you’re asking us to guess yours from a description. There are multiple places where your code or Workflow setup may be going wrong. Without looking at it we’re shooting in the dark. Read the Reporting Problems with Workflows topic, as it gives a nice overview on how to build an effective report. Link to comment
mort_the_swift Posted March 31, 2020 Author Share Posted March 31, 2020 (edited) My apologies. Here's the workflow: https://www.dropbox.com/s/3m7ahra6fc13hfi/IVPN.alfredworkflow?dl=0 Alfred 4.0.9 [1144] macOS Catalina 10.15.4 Edited March 31, 2020 by mort_the_swift Link appropriate workflow file Link to comment
vitor Posted March 31, 2020 Share Posted March 31, 2020 14 minutes ago, mort_the_swift said: Here's the workflow: https://www.dropbox.com/s/lc9fe92ygeno2z0/info.plist?dl=0 Not the info.plist, the exported Workflow. Link to comment
mort_the_swift Posted March 31, 2020 Author Share Posted March 31, 2020 @vitor My bad again. I have edited my previous post accordingly. Link to comment
mort_the_swift Posted April 9, 2020 Author Share Posted April 9, 2020 Was it something I did? 🙂 Just curious, if this is a known issue or a freak of nature. Link to comment
vitor Posted April 11, 2020 Share Posted April 11, 2020 There’s nothing glaringly obviously wrong with your Workflow setup, and since I don’t use IVPN, I can’t help you further. But having the correct Workflow available will allow whoever can help to start with the necessary information. Link to comment
mort_the_swift Posted April 12, 2020 Author Share Posted April 12, 2020 20 hours ago, vitor said: There’s nothing glaringly obviously wrong with your Workflow setup @vitor, Thank you for that at least. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now