Jump to content

Select last word then open alfred with selection


Recommended Posts

Is this possible? Basically I'm trying to invoke the keyboard shortcut alt shift left-arrow to select the word to the left of the cursor key. Then I want to start Alfred with the keyword "spell" and the just selected word. 

 

That would make a nice and simple spell checker (I hate the automated one). I could assign the whole workflow to a shortcut.

 

Is this somehow possible? 

Link to comment

If you add a Hotkey Trigger to a workflow, you'll see it has an Argument option. You can set this to "Selection in OS X".

 

Add such a Hotkey Trigger and connect it to a Run Script Action. Set Language to "/usr/bin/osascript" and paste the following into the Script box:

 

tell application "Alfred 2" to search "spell {query}"
 
Combining both actions (selecting text and running Alfred) would be relatively complex with Alfred, and less flexible (it would only work with the word just before the cursor). I'd recommend Keyboard Maestro for something like that.
Link to comment

Thanks for your message deanishe.

 

I posted a screenshot of a version that actually does what I want. Only downside is that when I invoke the shortcut I get a pop sound, that you would get when you try to do a shortcut that is not available. This is because when I invoke the shortcut nothing is selected and I try to push the selection into the Script. I'm aware that I'm not using it but else the workflow won't work.  

 

It's a hacky implementation but maybe somebody has an idea how to fix it?

 

Workflow.png

Edited by Flipsos
Link to comment

You could try adding short delays between the simulated keypresses. Such actions in AppleScript are asynchronous, so it's possible your script is proceeding before the intended action has been carried out.

 

You can also access the keyboard contents directly from AppleScript without having to simulate CMD+V to send the text to Alfred.

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