Jump to content

Running AppleScript unintentionally reopens Alfred bar efter closing

Recommended Posts

Edit: I realized that the thread topic is ambiguous. The problem I'm having is that including a certain AppleScript in my Alfred workflow makes the Alfred bar behave weird, refusing to go away.


I've made a workflow that uses a List Filter to open a set of URLs depending on the argument provided.


I also included an AppleScript that tells Evernote to open a certain notebook/stack. The script is visible as the /usr/bin/osascript in the image below.


When I run the workflow with the AppleScript attached to it, the Alfred Input Window closes but then displays again – with the previous input still there. It behaves very erratically each time, sometimes "blinking" on/off in perpetuity, which seems to be impossible to stop, except by rebooting the computer.


When I run the workflow without the Applescript attached, the Alfred Input Window closes normally.


Something seems to force the Alfred window to remain open. Is it a bug in Alfred, or something with the AppleScript and how it's implemented in the workflow?


Note that I didn't write the AppleScript myself, but it was retrieved from the forum link above. I understand that this isn't the proper forum for AppleScript support – but is Alfred behaving in an unexpected way here?


Thanks for any help!




on run argv
    set destination to "stack:Communications"

    tell application "System Events"
         -- Let's make sure Evernote is running. If Evernote needs to be started, wait a sec!
         if not (exists process "Evernote") then
              tell application "Evernote" to activate
              delay (3)
         end if
         -- Now let's invoke a collection window by starting a global search.
         keystroke space using {option down}
         delay (0.5)
    end tell

    -- Sometimes it needs a moment for a collection window to be created.
    -- As long as no collection window exists, trying to change its query string will result in an error.
    -- We'll simply try again until we succeed.

         set tryagain to true
              tell application "Evernote"
                   set query string of window 1 to destination
              end tell
              set tryagain to false
         on error
              tell application "System Events"
                   keystroke space using {option down}
              end tell
              delay (1)
              set tryagain to true
         end try
         if not tryagain then exit repeat
    end repeat
end run
Edited by winterflags
Link to comment

Are you using option-space as your hotkey for Alfred?  The script is trying to get Evernote to do something by simulating an option-space keypress in System Events.


Keen observation! That solved my problem, thanks.

Funny coincidence that they were using the same key combination, so I changed the one used in Evernote.

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...