Jump to content

Hotkey argument: OS X selection OR clipboard contents


Recommended Posts

Hi!

 

Sometimes I do several searches for the same piece of text using different hotkeys (with workflows opening respective search pages directly, without opening Alfred's window).

 

Would it be possible to add an argument option to Alfred hotkeys to try and get current selection first, and if nothing is selected, use clipboard contents instead?

 

Currently I have to assign two hotkeys for each workflow, one for selection and one for clipboard, which means wasting key combinations and having to remember too many hotkeys.

 

(The combination of sites I search varies all the time, so creating a single hotkey that would trigger several searches is not an option.)

Link to comment
Share on other sites

Interesting proposition. It is possible, yes, and should’t take much work. The trick is to set the Hotkey to pass the selection to the workflow, and before doing anything with it, check if it passed anything. If the passed argument is blank (will happen if nothing is selected), use the clipboard.

Example workflow, using bash.

For future reference (in case the download link goes down, or someone just wants the code), this quick check consists of

arg="{query}"
[[ -z "${arg}" ]] && arg="$(pbpaste)"

echo "${arg}"
Link to comment
Share on other sites

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