Jump to content

AppleScript does not work?

Recommended Posts

Hi guys, I wrote a little AppleScript that copies and pastes a text selection to the Alfred bar with a certain prefix: see below.


The thing is, when I select text, and run the .scpt file from the Alfred bar (i.e. I look up the file and press enter) it works fine, but when I try to link this  script to an Alfred keyword or hotkey, it stops working. I tried these three methods:


  • I simply copied the content of the .scpt file into an Alfred workflow (actions --> RunNSAppleScript). Doesn't work.
  • I wrote a bash script calling the .scpt file and attached it to the action  "run script". Doesn't work.
  • I used the action "open file" and attached the .scpt file to it. Doesn't work.


It's not that these three methods don't do anything. In fact weird things happen. The text selection expands to adjacent words for example. Or I hear the "beep" of the mac "alert sound". I also sometimes seems as if the delay of 0.5 does not work.


Its' not such a big deal. I can run the script by simply launching it by searching the file in the Alfred bar, but I'm still generally curious what is going on here. Any ideas?



tell application "System Events" to keystroke "c" using command down

tell application "System Events" to keystroke space using command down

delay 0.5

tell application "System Events" to keystroke "n"

tell application "System Events" to keystroke space

tell application "System Events" to keystroke "v" using command down


Link to comment

@Misha Could you clarify what you're actually trying to achieve? Given the range of objects in Alfred, it's likely that there's a better way to achieve what you want. Are you trying to open Alfred with the macOS selection, with it prefixed with the keyword "n"? If so, that's quite easy and would be much more reliable... (You'll just need to also set a hotkey, which I didn't do in this example)


Screen Shot 2017-07-04 at 17.20.11.png


Beyond that, Alfred has a built-in Dispatch Key Combo output object, a Delay utility object, etc, so you might be able to do what you need without AppleScript keystrokes. :)



Link to comment
  • 2 weeks later...

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