Jump to content

How to Web Search for Query with a Hotkey?


Recommended Posts

I searched on the internet and tried myself and I could not find how to do it. What I essentially want is just to be able to enter a hotkey and be presented with a web search on that site where I can type my query.

 

I thought it would be rather easy to do it and perhaps there would even be a preset made for something like this but for some reason it doesn't work. (ie if I do this (http://i.imgur.com/CMa3SPe.png)) it goes directly to the website and doesn't let me to actually type my desired query in the window. :(

 

What can I do to fix this? Thank you for any help. 

Link to comment

You can’t. What you want to do, in the way you’re trying to do it, simply does not make sense.

It is possible, though, but not without coding. There’s no way for Alfred (or any app, really) to know what the search box of any arbitrary website is. For that, you need to use javascript, and you’ll inform your browser of what you want with AppleScript. AlfredBookmarklet is made exactly for this.

For reddit (what you seem to be wanting), to focus on the search box you just need to document.querySelector('input[placeholder=search]').focus();. Unfortunately, while that’s working with Chrome, it’s not working with Safari (which seems to be what you use), for some reason. If you’re willing to use Chrome, follow the instructions for AlfredBookmarklet, and on step 3 paste the following:

tell application "Google Chrome"
  open location "https://www.reddit.com/r/webdev"
  delay 1
  tell active tab of front window to set the URL to "javascript:document.querySelector('input[placeholder=\"search\"]').focus();"
end tell
Increase the number in delay if the page loads slowly.
Link to comment

Thank you for your answer Vitor,

 

I don't really quite get why this requires so much stuff. I kind of thought that this would work (https://imgur.com/a/0LPU3). As essentially, what I think it will do, is allows me to type my query and then throw it into the web search replacing the {query} there with mine. However that did not work.

 

Also the code you produced with 'tell active tab of front window to se the URL' wouldn't quite work in my case as I want it to be global. Essentially I just want what Deanishe has done (http://www.packal.org/workflow/searchio) but without the autosuggest. However I tried looking at his workflow and I have no idea how he has done it as it just says (https://imgur.com/a/IBScs).

 

I really want to get into creating my own scripts for Alfred but right now I get so confused. I would of thought creating a simple web search by query would of been rather easy but it turns out it is not or perhaps I am just missing some things.

 

Thank you for your help again Vitor, I use your workflows quite often, most recently started using Webscreenshot so thank you for that. 

Edited by Nikita Voloboev
Link to comment

So you want to use a keyboard shortcut that will pop Alfred where you can type a query and it’ll search on that website?

That’s an odd way to do it. Why not use a custom web search?

The connections in your first screenshot also do not make sense. Script Filters aren’t meant for that. You should take a look at Alfred’s documentation to understand how each piece works and what’s their place in the chain.
 

I really want to get into creating my own scripts for Alfred but right now I get so confused.


Because you’re going the wrong way around. If you don’t have any scripting experience (which seems to be the case), you’re missing the bases of how and why Alfred workflows work a certain way, hence the confusion. To create your own more complex workflows, you should try to be comfortable at a basic level with the Terminal, at least. The Bash Academy is a recent initiative (and still very much a work in progress) to teach the bash shell (which is what your OS X Terminal uses by default), so it may be worth a look.

Either way, here you go. This should do what you want, and be simple enough to understand.

Link to comment

Wow thank you.

 

This is exactly what I wanted. The reason it may sound odd at first is that I want to then bind that hotkey to a gesture with BetterTouchTool. This really works out great for me.

 

I really want to thank you for putting the time in helping me with this this. It is very kind of you. This is exactly what I wanted (https://imgur.com/a/IdTVO). I will take a hard look into Bash Academy so I won't ask silly questions in the future. ♥

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