Jump to content
Gautam

Trim whitespace with 'web search'

Recommended Posts

I have a workflow to invoke alfred with selected text. I usually use the selected text with my web search keywords to open specific pages. One annoyance is that the selected text can contain white space at either end.

 

e.g. typing "imdb<space><space>godfather" in the alfred window search IMDB for "<space>godfather". 

 

 

This is not a problem with IMDB but it is with the web applications I use everyday. Please consider adding an option to trim leading/trailing white space when used with web search.

 

Share this post


Link to post

I currently use the single step workflow, created using Add Workflow (+) -> Templates -> Show Alfred -> Show Alfred with selected text. My changes to this was to change cursor position to 'left' and a custom hotkey. Based on your suggestion, I modified the action in it from "Show Alfred" to "Pass through to workflow". Indeed I was able to add a Trim Whitespace as the next step. However, for step 3, I can't add a "Show Alfred". Closest is "Browse in Alfred" which is not useful in this context. I'm probably missing the obvious, how can I get a "show alfred" as the last step with the selected text?

Share this post


Link to post
On 06/04/2018 at 1:40 PM, Gautam said:

how can I get a "show alfred" as the last step with the selected text?

 

With a Run Script Action and AppleScript:

tell application "Alfred 3" to search "{query}"

Share this post


Link to post

Thanks, I built on that suggestion (replaced {query} with q) and can Alfred to show with the trimmed selection. However I would like the cursor to reach the front of the text with a leading space so I can simply type my web shortcut keyword. Here's what I have. The commented lines don't work (123 is keyboard left, 49 is space bar)

 

on alfred_script(q)
  tell application "Alfred 3"
    search q
    activate
--  keycode 123 using command down
--  keycode 49
--  keycode 123 using command down
  end tell
end alfred_script

 

Share this post


Link to post

Run Script, not Run NSAppleScript. I'd be surprised if Run NSAppleScript worked at all, as you're now trying to call Alfred from Alfred's own main thread.


Don't use Run NSAppleScript unless there's a good reason to do so.

Share this post


Link to post

I did try to run a script (type osa) as well but doesn't accomplish what I want. I'll give up on this for now, thanks for your assistance.

 

 @deanishe  I'll give your Alfred Workflow library a try later.

Share this post


Link to post
10 hours ago, Gautam said:

I did try to run a script (type osa) as well but doesn't accomplish what I want. I'll give up on this for now, thanks for your assistance.

 

 @deanishe  I'll give your Alfred Workflow library a try later.

 

If you upload the non-working workflow and post a link to it, we can help you fix it.

Share this post


Link to post

Here's a working version. You may need to add a delay before firing the keystrokes to give Alfred time to appear first (otherwise the keypresses won't be sent to Alfred).

 

Share this post


Link to post

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
×