Friday, May 12, 2017

windows 10 - Hotkey to open File Explorer with search box focused?




In Windows 10, the behaviour of the standard file search, activated by pressing the Windows key Win, has completely changed with respect to Windows 7. It generally gives unsatisfactory and incomplete results as nicely illustrated e.g. in this PCGamer article.



One could use alternative free search tools like e.g. the higly regarded EVERYTHING software. However, I find that the search box of File Explorer already does exactly what I want. In fact the File Explorer search box returns results that are generally the same as EVERYTHING (see an example below), and it is equally fast. In addition File Explorer efficiently indexes and searches the content of files. For this reason I would like to use File Explorer for my standard file searches instead of third party products.



File Explorer vs. EVERYTHING search of full Miniconda folder



The small problem is that I use search constantly in my workflow, and it takes two hot keys to Win+E open File Explorer and Ctrl+F to focus on search. Moreover, this approach keeps opening new File Explorer windows, instead of reusing open ones.



Can somebody think of a simple way to have a single global hotkey, which:





  • opens File Explorer, or brings it to the foreground if already open; and

  • set the focus to the search box, so one can immediately start typing



to search for files?


Answer



If you are amenable to using a third party program...



Use AutoHotKey, which can combine keystrokes or hotkeys




The docs are quite readable, but this should get you started by binding Ctrl+F9 to focusing search in Explorer.



File explorersearch.ahk:



Open explorer and focus search



^F9::
Send, #e
WinWaitActive, ahk_class CabinetWClass

Send, ^f


Re-use explorer window



Or, a more involved one that uses WinExist to check if Explorer is open, and WinActivate to focus it:



^F9::
if WinExist("ahk_class ExploreWClass") or WinExist("ahk_class CabinetWClass")
{

WinActivate
Send, ^f
return
}
else
Send, #e
WinWaitActive, ahk_class CabinetWClass
Send, ^f



(thanks to JayG's answer at SO for the ahk_class used by explorer as I don't have Windows booted at the moment)



Where: # is the Windows key and ^ is the Ctrl key. WaitWinActive will wait until the Explorer window has focus (thanks to divenex for the suggestion, which replaced Sleep). Additionally, you could probably replace the first line with Run, explorer.exe for the same effect; but this does what was literally asked in the original question.



With AutoHotKey there is a huge scope for customisation and automation- it's worth reading through the tutorial, and you'll probably want to keep a note of the key and modifier list handy too.


No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...