Search in this path from context menu and with key shortcut

Have a suggestion for "Everything"? Please post it here.
Post Reply
soyo
Posts: 13
Joined: Wed Oct 22, 2014 9:33 am

Search in this path from context menu and with key shortcut

Post by soyo »

Hi

First of all, I discovered the app today, and it is really great! Thanks for it.

I wanted to ask you, if it would be possible to add the option to windows context menu for "Search in this path", after right clicking on empty space inside a folder or on any file within a folder. Also, going with this, an option for external keyboard shortcut, that would invoke automaticaly "Search everthing" window once pressed. So lets say, I have a folder C:\Temp opened in windows explorer, this explorer window has focus at this moment, and when pressed say... Win+F it would open "Search Everything" window with the path "C:\Temp" automaticaly inputed as prefix.

Possible?

cheers and again congrats on a very usefull tool.
Lucas
void
Developer
Posts: 16735
Joined: Fri Oct 16, 2009 11:31 pm

Re: Search in this path from context menu and with key short

Post by void »

I wanted to ask you, if it would be possible to add the option to windows context menu for "Search in this path", after right clicking on empty space inside a folder or on any file within a folder.
As far as I know the folder context menu in Windows Explorer can not be modified easily. I will look into this more..
Win+F it would open "Search Everything" window with the path "C:\Temp" automaticaly inputed as prefix.
I will consider adding this as an option.

Thanks for the suggestions.
soyo
Posts: 13
Joined: Wed Oct 22, 2014 9:33 am

Re: Search in this path from context menu and with key short

Post by soyo »

Thanks a lot for quick answer and an interest in my request feature. Hopefully it is doable, as it would be great improvement and much more convienient.

One thing I need to clarify. Ofcourse that "Win+F" part does not have to be handle by you alone. I mean, the most important is to provide that "Search in this path" functionality where you don't have to everytime go up one folder, click on the folder I was a second ago in, and then invoke "Search everything" on that folder. That's the main thing.

As for the "Win+F" part. If you could just give some entry point, so that we can achieve any shortcuts with say AutoHotkey or some global keyshorts functionality, it would be great.

Talking about this, I just thought of one thing... Is your app able to get input parameters when running the executable? Because if it does, I could try and use a temporary hackaround using AutoHotkey (still adding the "Search in this path" feature in context menu would be nice), where I would detect a windows exporer is opened and currently focused, and try to read the currently opened path within it (don't know if it's possible with AutoHotkey yet), and just pass this path and invoke search everything. So for my example from the topic, I would just run with AutoHotkey: "C:\Program Files\Everything\Everything.exe" "C:\Temp"
soyo
Posts: 13
Joined: Wed Oct 22, 2014 9:33 am

Re: Search in this path from context menu and with key short

Post by soyo »

Scratch the question ;)
http://www.voidtools.com/support/everyt ... e_options/

Nice!

So anytime you could look into adding an option in Everything for adding the "Search in path" entry in context menu would be great.
soyo
Posts: 13
Joined: Wed Oct 22, 2014 9:33 am

Re: Search in this path from context menu and with key short

Post by soyo »

Hopefully didn't break anything ;)

http://superuser.com/questions/830525/h ... 526#830526

Thanks again for creating this great tool.
therube
Posts: 4977
Joined: Thu Sep 03, 2009 6:48 pm

Re: Search in this path from context menu and with key short

Post by therube »

> Hopefully didn't break anything

Only at superuser as they removed the question ;-).
soyo
Posts: 13
Joined: Wed Oct 22, 2014 9:33 am

Re: Search in this path from context menu and with key short

Post by soyo »

Unbelievable.

A person tries to help others for totaly non-selfish reasons (just like you did with your app), spent time on it, and not only nobody thanked you for it, but even penalized you for it, for something totaly non-malicious. Amazing.

Well if anyone is interested, I will just paste the contents of my topic at superuser since I still have the access to it:
The "Search Everything" (http://www.voidtools.com/) is a fantastic free software, but it lacks a very basic thing, which is to "Search within the current path". Currently, if you wanted to search for the files inside the currently opened folder in windows explorer, say... "C:\Temp", you would have to manualy go up to "C:\", then select the Temp folder, right click on it, chose the "Search Everything" option and only after doing all that you would get what you needed.

Is there anything that could make this repeatitive procedure less painfull?
I thought there must be a better way to do this. I discovered a creator of this tool make an effort to support Command Line Options, and so I made a nice little AutoHotkey script which shortens all that procedure described into first paragraph to one keyboard shortcut.

Very important note is that the script is tested only on Windows7 x64, so I can't guarantee it will work on Windows8, WindowsXP etc.

The script obviously needs AutoHotkey to be installed on the machine, and the script has to be run on every Windows bootup (so the easiest way would be to copy the link to the script, or copy the whole script into Autostart folder) so that it can capture the keyboard shortcut. The shortcut is set for Win+F, but it can be easily modified within the script. One thing to keep in mind, the script depends on the path to the Everything.exe file to be under this path: "C:\Program Files\Everything\Everything.exe"

If it's somewhere else, modify that line.

When writing this script, I used as a backbone, this script: http://superuser.com/a/205368/172360

which was the only one I could find in all the web, that worked on my machine, and returned the path. I tweaked it a bit because it used the literal word "Address" unnecesearily and it was dependant on the local language used in the client OS which brought a big limitation and so I replaced it with regular expression to work on any locale (in theory ;)). Also the path had to be formated in the right way so I changed that. After that I added the relevant code for the SearchEverywhere app, added some comments too.

To "install" the script, you have to save it to a text file with the .ahk extension, and run it so that it can reside in background.

So as for the user experience, once you are all set, all you got to do, is press the shortcut (Win+F) with the Windows Explorer focused and the Search Everything app will be started with the relevant path entered automaticaly in the search box. If the currently focused window in windows is not explorer it will enter "C:\" "D:\" and "F:\" partitions for a "global search". If you have other partitions on your computer you will have to modify that part of the script manually to work with your OS instalation.

It works great, and I hope it will be beneficial to someone else, besides me. Enjoy.
;////////////////////////////////////////////////////
;\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
;****************************************************
;********* *************
;********* Written by: *************
;********* soyo/Luk *************
;********* *************
;********* Search everything: ver1_1_0 *************
;********* *************
;****************************************************
;\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
;////////////////////////////////////////////////////

#NoTrayIcon

SetTitleMatchMode RegEx
return

; Stuff to do when Windows Explorer is open
;
#IfWinActive ahk_class ExploreWClass|CabinetWClass

; When user presses Win+F in an explorer window, we Search Everything within this path
; If Other shortcut is required, it can be changed here
;
#f::
SearchEverythingInPath()
return
#IfWinActive

#IfWinNotActive ahk_class ExploreWClass|CabinetWClass

; When user presses Win+F in any other window, we start Search Everything to search within all partitions
; Currently set to search in C:\ D:\ and F:\
; If Other shortcut is required, it can be changed here
;
#f::
SearchEverythingForGeneralSearch()
return
#IfWinNotActive


; Invokes Search Everything app with the current path as the path argument
; Note: expecting to be run when the active window is Explorer.
;
SearchEverythingInPath()
{
; This is required to get the full path of the file from the address bar
WinGetText, full_path, A

; Split on newline (`n)
StringSplit, word_array, full_path, `n

; Find and take the element from the array that contains address
Loop, %word_array0%
{
FoundPrefixOccurance := RegExMatch(word_array%A_Index%, ".*:\\*")
if(FoundPrefixOccurance > 0)
{
full_path := word_array%A_Index%
break
}
}

; strip to bare address
full_path := RegExReplace(full_path, "^" ".*: ", "")

; Just in case - remove all carriage returns (`r)
StringReplace, full_path, full_path, `r, , all

IfInString full_path, \
{
; We remove the last backslash if there is any in the stipped path, this happens when the path is a root of a partition so
; for example "C:\"
full_path := RegExReplace(full_path, "\\$" "" )
; After we are sure we have a stripped path without the backslash at the end, now we can safely add a backslash
full_path = %full_path%\
; We run Search Everything with the path atribute
Run, "C:\Program Files\Everything\Everything.exe" -p "%full_path%"
}
else
{
SearchEverythingForGeneralSearch()
}
}

; Start Search Everything to search within all partitions
; Currently set to search in C:\ D:\ and F:\
SearchEverythingForGeneralSearch()
{
Run, "C:\Program Files\Everything\Everything.exe"
}
vsub
Posts: 474
Joined: Sat Nov 12, 2011 11:51 am

Re: Search in this path from context menu and with key short

Post by vsub »

I didn't read all but this method will not work if an option(which I don't think it exist on anything above WinXP)to show the folder path in the window title is not enabled.

Rather than relying on the title bar for the path,why not get it from the address bar(which exist in any windows version)
Here is a short version:

Code: Select all

#If (WinActive("AHK_class CabinetWClass") or WinActive("AHK_class ExploreWClass"))
#F::
KeyWait,F
ControlGetText,Path,Edit1,A
Run,C:\Program Files\Tools\Everything\Everything.exe -p "%Path%"
Return
Also I don't know if this works on Win7(I have XP)but right clicking at the folder icon(top left of the title bar)will display the context menu for the folder you are currently in and from there you can use the Everything context menu that already exist.
soyo
Posts: 13
Joined: Wed Oct 22, 2014 9:33 am

Re: Search in this path from context menu and with key short

Post by soyo »

I didn't read all but this method will not work if an option(which I don't think it exist on anything above WinXP)to show the folder path in the window title is not enabled.
I use this code on Win7 x64. So it does exist, at least for that OS.
Rather than relying on the title bar for the path,why not get it from the address bar(which exist in any windows version)
Here is a short version:
I used that code that is in my script because like I mentioned in the summary that was the only code I could find on the web which indeed was able to extract that path on my machine correctly. None other worked.

Same is with your sample. I included your code for testing purposes like so:
#IfWinActive ahk_class ExploreWClass|CabinetWClass

; When user presses Win+F in an explorer window, we Search Everything within this path
; If Other shortcut is required, it can be changed here
;
#f::
KeyWait,f
ControlGetText,Path,Edit1,A
MsgBox %Path%
;SearchEverythingInPath()
return
and the string under the %Path% I got, is this one:
https://www.dropbox.com/s/q6640khytcxmb ... k.png?dl=0

I would deffinetly prefer a cleaner way than to operate on the hardcoded string to extract the clean path so if you have a working way, then please share it.
Also I don't know if this works on Win7(I have XP)but right clicking at the folder icon(top left of the title bar)will display the context menu for the folder you are currently in and from there you can use the Everything context menu that already exist.
There is nothing of that sort on Win7.
vsub
Posts: 474
Joined: Sat Nov 12, 2011 11:51 am

Re: Search in this path from context menu and with key short

Post by vsub »

Either change the "Path" variable to something else,or add #NoEnv at the top of the script.

Without #NoEnv,a variable named "path" contains all of your environment variables.
In WinXP=>Right click on My Computer=>Properties=>Advanced=>Environment Variables=>in the System variables there is a variable named "Path" which contains all of those paths in the screenshot and unless you add #NoEnv,you will get them instead of the path from the address bar

http://www.autohotkey.com/docs/commands/_NoEnv.htm
soyo
Posts: 13
Joined: Wed Oct 22, 2014 9:33 am

Re: Search in this path from context menu and with key short

Post by soyo »

Thanks for additional tips and taking the interest in the first place.

Your explanation makes perfect sense. However, I changed the name from "Path" to "my_path", so:
#IfWinActive ahk_class ExploreWClass|CabinetWClass

; When user presses Win+F in an explorer window, we Search Everything within this path
; If Other shortcut is required, it can be changed here
;
#f::
KeyWait,f
ControlGetText,my_path,Edit1,A
MsgBox %my_path%
;SearchEverythingInPath()
return
Now the result is:
https://db.tt/WyC7MizI

If I leave the name to "Path" and add the #NoEnv directive, it doesn't change anything. Still the %Path% is empty. It is something I saw with some of the scripts I previously found on the web.
vsub
Posts: 474
Joined: Sat Nov 12, 2011 11:51 am

Re: Search in this path from context menu and with key short

Post by vsub »

I have one guess.
Try tying something in the search bar(there is no such thing in WinXP)at the upper left and then press the hotkey.
If you get the text from the search bar,then that means the control name for the address bar is not Edit1 but something else.

Try this

Esc::
Keywait,Esc
MouseGetPos,,,,Control
Msgbox,% Control
Return

Press the Esc button after you click on the address bar and don't move the mouse after that and replace the Edit1 from the other script with the variable you get from this code
soyo
Posts: 13
Joined: Wed Oct 22, 2014 9:33 am

Re: Search in this path from context menu and with key short

Post by soyo »

Ok, I got that info for you.

1) When I do as I did prior I get the empty string:
https://db.tt/sciAeiCQ

2) Now when I click on the search field or just highlight that box, I get the correct path:
https://db.tt/eTXkwr64

Keep in mind that if I go into some folder in that path, and I repeat step #2, I get the same path that I got prior. I have to hightlight search box again to get the updated path.

3) When I added your code to check for the control name I got "Edit1":
https://db.tt/3SQWrgTD

so it would seem the problem is not with the name of the box control.
vsub
Posts: 474
Joined: Sat Nov 12, 2011 11:51 am

Re: Search in this path from context menu and with key short

Post by vsub »

No need to post screenshots...Ctrl+C while the msgbox is active will copy the text,the title of the msgbox and the button text.

What name do you get when you do this:
1.Close all explorer windows
2.Open one
3.Move the mouse over the address bar but not click on it and press Esc(the code for the esc button)?
soyo
Posts: 13
Joined: Wed Oct 22, 2014 9:33 am

Re: Search in this path from context menu and with key short

Post by soyo »

---------------------------
SearchEverythingFromThisPath.ahk
---------------------------
ToolbarWindow322
---------------------------
OK
---------------------------
vsub
Posts: 474
Joined: Sat Nov 12, 2011 11:51 am

Re: Search in this path from context menu and with key short

Post by vsub »

And what do you get from this while explorer window is active

#f::
KeyWait,f
ControlGetText,my_path,ToolbarWindow322,A
MsgBox %my_path%
return

I've never used AHK on anything other than WinXp so I don't know how it works there(what control names are used there)

You can also try this

1.Get the path from some folder with long path(copy it to the clipboard)
2.Close all explorer windows
3.Open the folder you get the path from.

Run this code while that folder is active

Code: Select all

Esc::
WinGet,List,ControlList,A
Loop,Parse,List,`n
{
ControlGetText,CT,% A_LoopField,A
If CT = %Clipboard%
Ctrls .= A_LoopField "`n"
}
MsgBox,% Ctrls
Return
This will display all of the controls that contains the path which is in the clipboard(ComboBoxEx32? is probably the best place)
soyo
Posts: 13
Joined: Wed Oct 22, 2014 9:33 am

Re: Search in this path from context menu and with key short

Post by soyo »

vsub wrote:And what do you get from this while explorer window is active

#f::
KeyWait,f
ControlGetText,my_path,ToolbarWindow322,A
MsgBox %my_path%
return
---------------------------
SearchEverythingFromThisPath.ahk
---------------------------
Adres: C:\
---------------------------
OK
---------------------------

So a first row of what I get in the algorythm I used in my script.
I've never used AHK on anything other than WinXp so I don't know how it works there(what control names are used there)

You can also try this

1.Get the path from some folder with long path(copy it to the clipboard)
2.Close all explorer windows
3.Open the folder you get the path from.

Run this code while that folder is active

Code: Select all

Esc::
WinGet,List,ControlList,A
Loop,Parse,List,`n
{
ControlGetText,CT,% A_LoopField,A
If CT = %Clipboard%
Ctrls .= A_LoopField "`n"
}
MsgBox,% Ctrls
Return
This will display all of the controls that contains the path which is in the clipboard(ComboBoxEx32? is probably the best place)
Sure I could do that, but I'm not sure what that will get us. The premise was good as to find a more universal method to get that path, and maybe more elegant. But we already saw Edit1 does not work in my case. However that window title is there since Win7 and up, so unless they will change that in Win10 it should continue to work. Obviously it would be great to find a solution that would also handle WinXP and say Vista (most likely Vista will be simmilar to Win7) and if you want to pursue it, then please feel free to do so. However even if I find some other control which encapsulates that path, we don't have guarantee WinXp has this control also, so it's a bit of a vicious circle here. I'm happy with the solution I found, which works great, and will keep it at that. I appriciate taking the interest.
vsub
Posts: 474
Joined: Sat Nov 12, 2011 11:51 am

Re: Search in this path from context menu and with key short

Post by vsub »

The point of my last script is to display the names of all controls that contains the path.

There is another method but I don't really like it because it get the text from all controls one by one but it's probably the 100% sure method to work everywhere

Code: Select all

#If (WinActive("AHK_class CabinetWClass") or WinActive("AHK_class ExploreWClass"))
#F::
KeyWait,F
WinGet,List,ControlList,A
Loop,Parse,List,`n
{
ControlGetText,CT,% A_LoopField,A
If CT not contains :\
Continue
IfExist,% CT
{
MsgBox,% CT
Break
}
}
Return
soyo
Posts: 13
Joined: Wed Oct 22, 2014 9:33 am

Re: Search in this path from context menu and with key short

Post by soyo »

Thanks for the script. I tested it, and

1) It only shows MsgBox when I click on the search box. If I just open MyComputer, navigate to say C:\, then the MsgBox doesn't show at all

2) It needs the searchbox to be clicked everytime you navigate to other folder, otherwise the path extracted is not updated in the string
Post Reply