Trigger a Google Verbatim search with keyword as parameter?

Hi all,

I'm fairly new to Keyboard Maestro and by no means a tech wizz.

That being said, I am trying to create a macro that will take a search term as parameter and then open Google in the default browser, looking for said search term with the "Verbatim" search enabled. (This will prevent Google from "intelligent" guess work)

I know that I can tell Google to search Verbatim by appending ?tbs=li:1 to a search string. However, I cannot figure out how to formulate the correct URL for this :confused:

I have tried the "Search the Web" action with the following:

https://www.google.de/webhp?hl=en&complete=0&tbo=1&num=50&tbs=li:1

Unfortunately, I do not know how to integrate the actual search term into this.

Any suggestions? I would really like to get this one going.

Thanks!
Alexandra

I believe you want to insert q=yoursearchtermhere& between the webhp? and the hl=en& bits of the string.

You may need to replace any spaces in your search term with %20 but I think the filter action can do that for you automatically.

Thank you Vincent. I very much appreciate your help.

Do you have any idea how I can tell Keyboard Maestro / Google to interpret q=yoursearchtermhere as a variable?

The URL

https://www.google.de/webhp?q=yoursearchtermhere&hl=en&complete=0&tbo=1&num=50&tbs=li:1

will populate the Google search field with "yoursearchtermhere.

I have tried "escaping" the query string like so:

https://www.google.de/webhp?q={search}&hl=en&complete=0&tbo=1&num=50&tbs=li:1
https://www.google.de/webhp?q=%s&hl=en&complete=0&tbo=1&num=50&tbs=li:1

and
https://www.google.de/webhp?q={%s}&hl=en&complete=0&tbo=1&num=50&tbs=li:1

but, alas, those won't work.

Hi @akl - I've put together a simple demonstration macro for you that I think achieves what you're trying to accomplish. I’m grateful to @vincent_ardern for his suggestion as I wouldn’t have known how to do this otherwise. Here’s the macro:

Test Google Literal Query.kmmacros (2.9 KB)

Click to see macro

Once you've installed the macro you'll need to first enable it and also assign a trigger.

The Set Variable action shows how to incorporate the percent-encoded search term as a variable when constructing the URL for Google.

You can use this as a basis for your own solution.

Let us know how you get on!

2 Likes

Wow, @tiffle, this is exactly what I was after. Thank you both so much, you've made my day :tada:

1 Like

@akl,

Not to even attempt to grandstand my main man @tiffle, however, I wanted to remind some and educate others that you can use the Trigger by name Action by using the macro name followed by the //, to add your parameter, and not need the user prompt.

The wiki says " You can pass parameters (v8+) to the macro via the %TriggerValue% token by adding // and then the parameter to your search string. The // and anything after that will be ignored in the search."

Basically replace the Prompt for User input with the following.
Set Variable to Text.kmactions (486 Bytes)

image

To run the above macro using @tiffle's macro name, you would hit your Trigger macro by name hotkey (mine is F19), type the macro name, type //your parameter and hit enter. As soon as you type Test goog, KM will see your macro (machine learning) and all you would have to do is type // and your parameter.

Typing the full name:

KM's Machine learning:

Either way is fine, this just saves a little time. I use the Trigger Macro by name with the Trigger Value for a ton of KM uses. You can see this post for more information.

I hope I simply added to the discussion.

Take care,
KC

3 Likes

That's a great improvement and a very practical extension to my suggestion, @kcwhat :+1:

I had forgotten this neat trick which could have been invented for this very purpose. I had forgotten all about it so thanks for the reminder!

PS: looking at the post you linked to (which I've now bookmarked) I see I :hearts:ed it originally - and I still do!

2 Likes

Thanks, KC, you guys absolutely rock :blush:

1 Like