Gautam Posted April 6, 2018 Share Posted April 6, 2018 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. Link to comment
Vero Posted April 6, 2018 Share Posted April 6, 2018 @Gautam Between your hotkey object and your action, add a Utility > Transform > Trim Whitespace https://www.alfredapp.com/help/workflows/utilities/transform/ Cheers, Vero Link to comment
Gautam Posted April 6, 2018 Author Share Posted April 6, 2018 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? Link to comment
deanishe Posted April 8, 2018 Share Posted April 8, 2018 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}" Link to comment
Gautam Posted April 8, 2018 Author Share Posted April 8, 2018 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 Link to comment
deanishe Posted April 9, 2018 Share Posted April 9, 2018 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. Link to comment
Gautam Posted April 11, 2018 Author Share Posted April 11, 2018 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. Link to comment
deanishe Posted April 11, 2018 Share Posted April 11, 2018 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. Link to comment
Gautam Posted April 16, 2018 Author Share Posted April 16, 2018 Here's the exported workflow: https://www.dropbox.com/s/fndsrh1ec4lvzz1/Show Alfred with selected text.alfredworkflow?dl=0 Thanks, Gautam Link to comment
deanishe Posted April 16, 2018 Share Posted April 16, 2018 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). Gautam 1 Link to comment
Gautam Posted April 16, 2018 Author Share Posted April 16, 2018 Many thanks! Does what I need. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now