Powertoys: [Run] Be able to launch a web search

Created on 20 May 2020  ·  42Comments  ·  Source: microsoft/PowerToys

Summary of the new feature/enhancement

I want to be able to start a web search from the launcher.
Ideally, I'd type bing power toys and it would navigate to https://www.bing.com/search?q=power+toys in my default browser.
google power toys would go to the equivalent.

The ability to specify the keyword/search engine to use and the domain it goes to would also be necessary. Not only would this enable supporting other search engines, but it would also allow for people to adjust for different TLD versions of search engines.

_This would be similar to functionality that used to be available in Enso launcher._

Proposed technical implementation details (optional)

This would presumably require some settings for determining which words are identified as initiating the search and the URL to submit the query to.
This could also be the base for similar functionality where a keyword could launch an app and pass other values as command-line arguments. Without additional arguments, this could also serve as a way to create aliases for apps so they could be launched with a small number of keystrokes.

Idea-Enhancement Issue-Feature Product-Launcher Run-Plugin

Most helpful comment

How about using a _?_ char to to switch to a web search mode like _>_ goes to a shell?

All 42 comments

Yes! Also it would be great if I could just write a longer sentence/string and it would always default to web search when it doesn't find other results. So basically, it should be like Windows Search 😅

This function is very practical. Hope to realize it

Yes, just like Alfred on Mac does!

So basically, it should be like Windows Search

And it would be fantastic if it would leverage the system default browser's chosen search engine, instead of picking one for itself.

How about using a _?_ char to to switch to a web search mode like _>_ goes to a shell?

that could be a shortcut to default search engine, but multiple ones should be supported with own keywords

Please give the option to disable this. Not everyone wants to automatically expose every local search query to a search engine on the internet.

This is, by the way, a big privacy insult in the windows start menu search, because you can't disable web search anymore.

See also #3420 that someone posted. I have a ton of web shortcuts in the browser and it would be nice to be able to run them natively in the launcher, optionally with the ? or # or other user defined character beforehand so powertoys understands I'm gong to be running a search engine.
One thing to consider would be how it knows which browser to use - to further muddy the waters would modifiers launch a particular browse so '# c powertoys' launches chrome (the 3) and then runs the c shortcut to search chocolatey's website for powertoys. Using '? int passwords" would then launch edge to search the intranet for passwords (as an example)

Please give the option to disable this. Not everyone wants to automatically expose every local search query to a search engine on the internet.

This is, by the way, a big privacy insult in the windows start menu search, because you can't disable web search anymore.

While windows search automatically loads the results the proposed functionality here is having the option to search your query through PowerToys Run, but it would not do that automatically, you still need to hit enter on the web search option, so all your queries remain private unless you explicitly ask to open a browser and search on google.

One thing to consider would be how it knows which browser to use

The query "> url" already opens a url in the default browser, so I think the issue of detecting which browser to use has been already solved

it just uses system call run or anything like that and OS itself resolves that

Would love to see this:

With keywords b, g, d for doing a query in the corresponding search engines and listing the results.

As a last resort if nothing could be found, on enter send query to default search engine

, but it would not do that automatically, you still need to hit enter on the web search option, so all your queries remain private unless you explicitly ask to open a browser and search on google.

Yes, as a possibility it's a feature. I thought about getting web results as soon as you start typing or doing a web search automatically in addition.

I think it's a very dangerous idea to force web results in a local search without an option to disable it, like the Windows search is doing it since some versions. It's a possible way to leak information unwanted from your computer. You could disable web search in the past, but it was removed some versions ago. On macOS you can set the search providers for the search like you want: only local, with web search, with wikipedia,... That's the better approach and everyone can set it up like wanted.

One thing to consider would be how it knows which browser to use

The query "> url" already opens a url in the default browser, so I think the issue of detecting which browser to use has been already solved

Thanks for the tip! but You need to prefix it with "WWW" 😞 . If I am not wrong! I think having identified that entered text is an URL opening that with the default browser will be a clean approach.

I am a big fan of the implementation of the web search functionality in Wox, where the user can define any random search using keywords and search URLs. So I have, for example, a web search to search Canadian case law using the https://www.canlii.org/en/#search/id={q} search URL, and I can trigger that by typing "canlii" plus the search query, then there is another search in the English Wikipedia using "wen" and the https://en.wikipedia.org/wiki/{q} search URL, or a third one searching in the German Wikipedia using "wde" and the https://de.wikipedia.org/wiki/{q} URL.

There's lots you can do here. Rather than get bogged down in detail, how about this basic functionality for a first version:

  1. User presses <Alt><Space>.
  2. User starts typing in the edit box. Power Toys Run displays what it currently displays from the shell. No change.
  3. If the user presses <Enter>, Power Toys Run does what it currently does. No change.
  4. If the user presses <Ctrl><Enter>, Power Toys Run opens the default browser, passes the string from the edit box to the default search engine and the search results are shown in the browser.

This is roughly what Google Desktop for Windows used to do before it was discontinued. It gives us a quick way to search for something on the web. I suspect it's the primary use case.

The one complexity is that I'm not sure the user's default search engine is discoverable without custom code for each browser. In which case, one of the settings in Power Toys would be to choose a default search engine. Version 1 can have a list of pre-defined ones (not customisable) to keep it simple.

Version 2 can introduce custom search engines and more sophisticated ways of searching the web such as prefixing the search by a letter (alias) to use a particular web site eg

b <search string> to search using Bing
w <search string> to search Wikipedia

and so on. For this, the Settings would allow the addition of aliases, such as:

Alias  URL
b      https://www.bing.com/search?q=%1
g      https://www.google.com/search?q=%1
w      https://en.wikipedia.org/wiki/%1
a      https://smile.amazon.co.uk/s?k=%1

where %1 is replaced by the search term entered by the user.

For version 3, you could have the option of including web history as the user typed a search term.

@Praful

There's lots you can do here. Rather than get bogged down in detail, how about this basic functionality for a first version:
...

i think this is a great idea to have aliases. I like syntax of DuckDuckGo Bangs which have a leading ! to distinguish a command from a regular input.

info: https://duckduckgo.com/bang

Auto complete feature is necessary.
Please see this issue:
https://github.com/microsoft/PowerToys/issues/4531

One can get PTRun to launch web URLs using a work around. Just documenting it here for reference if other people search and hit this page.

Summary

Firstly. we need to choose a prefix. In my example below, I use g as the prefix. Then, create an exe or batch file using this prefix, ie, g.exe, g.cmd or g.bat. However, if it is a batch file, then PTRun will require you to specify the extension as part of the prefix. You can choose gl.exe or web.exe or whatever you like for your prefix/program. Just don't have it clash with another existing program or prefix.

Secondly, this prefix exe or batch file needs to be in your path environment. For this example, I use %LOCALAPPDATA%\Microsoft\WindowsApps, but it works equally well if you choose C:\Windows\System32 (but I don't recommend it).

Finally, in order for PTRun to pass on the url parameter, we need to tell it to use the command processor with the > prefix when calling it (as described in #3405 - @edhcah example with Notepad++ didn't work because notepad++.exe wasn't in the path)

Method 1 - Soft Linking directly to Chrome

  1. Open an Admin Command Prompt
  2. cd "%LOCALAPPDATA%\Microsoft\WindowsApps"
  3. mklink g.exe "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
  4. mklink chrome_proxy.exe "C:\Program Files (x86)\Google\Chrome\Application\chrome_proxy.exe" (needed for Chrome to work)
  5. Test it out in PTRun:
  • Open a new blank browser window: > g
  • Open a URL: > g wikipedia.com or > g https://www.youtube.com/watch?v=dQw4w9WgXcQ
  • Open a Google Search: > g "? microsoft powertoys"

Method 2 - Batch File for Default Browser

If you prefer to use the system default browser, or do not wish to create symlinks, then you can add this batch file into %LOCALAPPDATA%\Microsoft\WindowsApps

  1. Create a new file %LOCALAPPDATA%\Microsoft\WindowsApps\g.cmd
@echo off
set _url=%1
if /I "%_url:~0,4%"=="http" (
    start "" %_url%
) else (
    start "" https://%_url%
)
  1. Test it out in PTRun:
  • Open a new blank browser window: > g.cmd
  • Open a URL: > g.cmd wikipedia.com or > g.cmd https://www.youtube.com/watch?v=dQw4w9WgXcQ

Next Step

One can of course convert the batch file to a proper CLI exe or extend it to do a Google search, but this solution is merely an interim hack until PTRun has proper support for this feature. In the mean time, this same principle can be used for other browsers/programs/etc, etc. For example, you can modify this concept to launch python scripts (via python.exe in %LOCALAPPDATA%\Microsoft\WindowsApps) or WSL shell scripts via wt.exe (eg. start/stop WSL httpd/MariaDB services from PTRun).

Tested working in version PT 0.19.2 / Chrome 83

I am just wondering, Why wouldn't I though about It, I had kept chrome as my startup program and had set my email domain as the default page. 🤦‍♂️🤦‍♂️

I'd like to see functionality similar to Launchy, where a string is detected as potentially searchable and the actions available for that string appear below in the search results. Those actions could be customized by the user, including some of the more advanced cases I've read from everyone. i.e. Targeted browser, engine or as input to interpolation, lexing and/or semantic analysis.

This approach acknowledges privacy concerns for out of box functionality. Customization involving downstream analysis would be a risk for the user or org to take on.

Would love to see this as well! I think the ? idea is particularly clean.

To throw in my two cents, I typically enjoy the Windows Search functionality, where a query that isn't recognized as anything else gets passed to a web search. I press one key, type my query, then hit enter and I immediately have the web results. I barely think about it. Only change I would make is browser/search engine choice. Obviously, restriction to Bing or Edge would be frowned upon in this project.

Yeah, I am expecting something like
image
and may be in setting we can have option to enable/disable web search!

something new? not possible to search with google at the moment?

The ability to define custom web queries is one of the simplest and most useful features for a launcher like this... see Wox or Alfred on Mac.

In my opinion custom alias should not have a hardcoded prefix like ! or ? or #. If people want that they can add them to their alias, but we shouldn't be forced to use them.

My two cents: A ? prefix would definitely be better than nothing, but personally I prefer having a dedicated "launch web search" keyboard shortcut. Shift+Enter (for instance) right after my query feels much faster than typing a question mark and an additional space at the beginning.

I think so a possible way to do so is get the query written inside the search box and add the selected search engine query to it. So for example if the user enters google power toys than the google keyword can be detected and removed. Than using the detected google keyword, the search engine link can be added into the ammended string, so it becomes 'https://www.google.com/search?q=power toys', the space is automatically replaced with %20 by the browsers. This can then be transferred to the shell where it will open the link up in the default browser

Please give the option to disable this. Not everyone wants to automatically expose every local search query to a search engine on the internet.

This is, by the way, a big privacy insult in the windows start menu search, because you can't disable web search anymore.

@kraoli

there shouldn't be a preview of the search, so the query only gets exposed when you press on it. but yes, an option to disable it would definitely be nice

_edit: clarity_

Definitely there should be the possibility like in Wox for Windows and Alfred for MacOS to just type a query and already get possibility to look it up on a preselected browser (PLEASE USE CHROME, NOT EDGE) most importantly when the query does not match any other possible request e.g. looking for a file, app, etc.

I think that adding the keyword like (g what is.....)would be a waste of time because it's faster and more practical to just write what you are looking for.

Maybe also add the possibility to search for a query on private tabs

+1 for this feature.

I would like this to work similarly to Alfred (on mac): if your local search does not return anything, hitting enter will launch the browser, and search your query on google.

A toggle for this makes sense as well :)

+1 for this feature. This should definitely be an option.

For people looking for a quick fix, here's an autohotkey script that will replace qq with the google search URL inside powertoys run.

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

#IfWinActive, PowerLauncher
:*:qq::https://www.google.com/search?q=

@crutkas @enricogior Would you be comfortable with me porting the Wox.Plugin.WebSearch, as I did with Wox.Plugin.Sys?

For people looking for a quick fix, here's an autohotkey script that will replace qq with the google search URL inside powertoys run.

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

#IfWinActive, PowerLauncher
:*:qq::https://www.google.com/search?q=

How would we run this in Power Toys Run?

How would we run this in Power Toys Run?

@engrbugs The macro replaces the current query text (iff PowerToys Run is the active window) with the basic Google search query string. Then you can type your query and press Enter. PowerToys Run detects it as a URL and opens it in the browser.

@micahmo Thanks! I installed AHK and put the scripts in the Windows Startup folder. I added some in the script:

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

#IfWinActive, PowerLauncher
:*:qq::https://www.google.com/search?q=
:*:tt::https://www.thesaurus.com/browse/
:*:yt::https://www.youtube.com/results?search_query=

@micahmo Thanks! I installed AHK and put the scripts in the Windows Startup folder. I added some in the script:

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

#IfWinActive, PowerLauncher
:*:qq::https://www.google.com/search?q=
:*:tt::https://www.thesaurus.com/browse/
:*:yt::https://www.youtube.com/results?search_query=

What is AHK and @micahmo, how to implement this. Is this a script that just needs to be put in notepad and saved. But then what is the extension of the script to be saved.
Is it so that it is a script that when put in the startup folder, launches at startup, checks if power run is the active window and then replaces the text 'qq' with the google search url?
What is the extension of the script and what is AHK?

@cursedsoulofgods

What is AHK

AHK or AutoHotkey is a powerful scripting utility, most often used for macros and custom keybinding. Download here.

Is this a script that just needs to be put in notepad and saved.

Yep.

But then what is the extension of the script to be saved.

AutoHotkey scripts have .ahk extension.

Is it so that it is a script that when put in the startup folder, launches at startup

Exactly. To activate a script, you just run it (assuming the .ahk extension is linked to the application), or put it in the startup folder so that it runs automatically. You should also see an icon the system tray for each active script, where you can pause/quit/etc.

checks if power run is the active window and then replaces the text 'qq' with the google search url?

Yes, that's what @smuun's script does when active.

BTW, Windows startup folder is either %appdata%\Microsoft\Windows\Start Menu\Programs\Startup for the current user, or %programdata%\Microsoft\Windows\Start Menu\Programs\StartUp for the all users.

In reply to @micahmo reply to my comment

assuming the .ahk extension is linked to the application

What do you mean by the AHK being linked to the application? Are there any special procedures for it?

@cursedsoulofgods

assuming the .ahk extension is linked to the application

What do you mean by the AHK being linked to the application? Are there any special procedures for it?

Sorry, I should've omitted that statement as it's more confusing than helpful. :) If you install AutoHotkey, it will automatically become the default application for .ahk files.

@cursedsoulofgods

assuming the .ahk extension is linked to the application

What do you mean by the AHK being linked to the application? Are there any special procedures for it?

Sorry, I should've omitted that statement as it's more confusing than helpful. :) If you install AutoHotkey, it will automatically become the default application for .ahk files.

Ok thanks @micahmo

Was this page helpful?
0 / 5 - 0 ratings