andreavaccari Posted August 16, 2021 Share Posted August 16, 2021 (edited) Hi, I have the following AppleScript app that I registered as my default browser: on open location _url tell application id "com.runningwithcrayons.Alfred" to run trigger "open" in workflow "com.andreavaccari.openlink" with argument _url -- delay 5 end open location The workflow that is invoked shows a list filter that allows me to pick which browser and mode to use to open the link. The workflow works correctly when triggered from another workflow or from the command line with `osascript`, but not when triggered from inside the `open location` even handler. What happens in this case is that the Alfred window appears for a split second but closes immediately because the `tell application` instruction is non-blocking and the subroutine ends. I confirmed this by adding a delay (commented above). In this case the window will show for 5 seconds and then close by itself. I found this comment by @deanishe on how to check if Alfred has a window open. This does not work because the `tell application "System Events"` is non-blocking. What is needed is a `repeat` loop that checks inside its body if there search window is open and breaks out otherwise. I have tried tried and failed to find the right AppleScript incantation. The script should look something like this (but again this does not work): on open location _url tell application id "com.runningwithcrayons.Alfred" to run trigger "open" in workflow "com.andreavaccari.openlinkwith" with argument _url repeat tell application id "com.runningwithcrayons.Alfred" if not (exists window 1) then exit repeat end if end tell delay 0.1 end repeat end open location Does anyone know how to achieve this? Thank you in advance for your help! Edited August 19, 2021 by andreavaccari I better understood the nature of my issue and I'm asking for more concrete advice 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