Jump to content

Google Suggest Workflow - How to Search for Typed Query Only?

Recommended Posts

Hi all,


I am using the 'Google Suggest' workflow which I installed via the '+' then the 'Examples' menu in the Workflows part of Alfred preferences.


It has a keyword of 'g' to initiate the search and is my default way of searching the web at the moment.


My question is: is it possible to submit a search to Google (using this workflow) of what I have actually typed, rather than one of the suggestions the workflow has presented (if the suggestions don't include what I'm looking to search for)?


Example: I want to search for 'EFF' so type this in. The suggestions which appear below don't include 'EFF' (it presents suggestions such as 'efficacy' and 'effect', but 'EFF' itself is nowhere to be seen) so I am not actually able to search for 'EFF' using this workflow.


I'm guessing the script this workflow runs would need to be amended to accomodate this preferred way of searching, but it's beyond my knowledge level so any suggestions would be appreciated.



Screenshot 2021-08-07 at 19.01.33.png

Link to comment

I'm guessing the script this workflow runs would need to be amended


You would be correct. If you open the workflow in Alfred, then double click on the first block (it says script filter) and paste this line below the line that says $int = 1; then save. It will then show your typed input as as the first option


// the rest of the code
$int = 1; // you should see this line in there already

// paste this line in below the above
$wf->result( $int.'.'.time(), "$orig", "$orig", 'Search Google for '.$orig, 'icon.png'  );

// the rest of the code



Edited by rknightuk
Link to comment

Just out of interest @rknightuk, bearing in mind that the around 80% of the time the right suggestion IS there at or towards the top of the list, would there be another way to do this whereby the suggested list remains as it was (without the modification you've provided above) and the typed-in phrase is searched for by pressing a modifier + the return key (cmd+return for example)?


This is just me scratching an itch and trying to figure out how things work...I think logically the below may work but I can't figure out, in the Script Filter action, how the typed-in phrase is set as a variable which could then be passed through to the cmd+return route?


Thank you.


Screenshot 2021-08-08 at 14.14.53.png

Link to comment

You're on the right track there but you would need to do one of two things:


1. Set the "input" as a variable, although this would be a little difficult given the way to workflow works, so I'd say this isn't ideal

2. Set the `mods` on the script filter (https://www.alfredapp.com/help/workflows/inputs/script-filter/json/) to the cmd key (or whatever you want)


I had a look in the `workflows.php` file which is what powers this workflow and it doesn't support the `mods` section when creating a result. I think this is a limitation of `SimpleXmlElement` but I could be wrong (it's been a while since I've used that).


Give me 15 minutes or so and I'll see if I can come up with something and I'll comment the code so you can see what I've done to achieve this.

Link to comment

Here you go @JA_UK https://github.com/rknightuk/alfred-workflows/raw/main/workflows/_misc/Google-Suggest-with-CMD-mod.alfredworkflow


Few things to make this work with this workflow:


Pass in the `$orig` query to the `result` method in the script filter


$wf->result( $int.'.'.time(), "$data", "$data", 'Search Google for '.$data, 'icon.png', 'yes', null, null, $orig );


Add the `mods` section so holding command will search for the original query (line 454-ish of workflows.php)


'mods' => [
	'cmd' => [
		'arg' => $orig,
		'subtitle' => "Search Google for $orig"


Thirdly, make this output as JSON instead, which supports the `mods` in the output


public function toJson()
	return json_encode([ 'items' => $this->results ]);


Link to comment

Hello and thanks again @rknightuk, that works - though in a slightly unexpected way.


Scenario A


Whilst typing if there are at least some search suggestions in the list, and I press cmd+return, a search is carried out on the typed-in phrase (as is now expected with your amended workflow):




Scenario B


If, however, there are no suggestions in the list, pressing cmd+return performs a search on <null> when the browser tab opens, so no search is actually completed:




Scenario C


If, however, I press just return (with no cmd modifier) a search is actually carried out on the typed-in phrase:




Would it be possible for the script to be amended so that in Scenario B (as well as Scenario C) a search gets carried out on the typed-in phrase?




Link to comment
  • 2 months later...

Hi again!


Just upgraded my Mac to macOS Montery (v12.0.1) and when I try to run this workflow (at the point I start to type in the search query) I get the following error from Alfred:


Reason: launch path not accessible


Check that the selected language exists on your system.

If you're syncing Alfred's preferences, also check that all related workflow files exist locally.

Related Workflow Info...
Name: 'Google Suggest (with CMD mod)'
Folder:/Users/<my home folder>/Dropbox/Alfred/Alfred.alfredpreferences/workflows/user.workflow.71110EE1-B84D-4C84-89D8-C20B89F3AE42


I'm guessing this is probably something to do with the new OS, but any help appreciated.



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