Jump to content
winterflags

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!

 

LvNf6QB.png

 

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.


    repeat
         set tryagain to true
         try
              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

Share this post


Link to post

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.

Share this post


Link to post

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.

Share this post


Link to post

Oh good. I've spent way too much time debugging AppleScripts that use various key presses, so when I saw the keystroke command there, it looked like a likely culprit

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...