如何加速“搜索一切”的主要功能

如何加速“搜索一切”的主要功能

“搜索一切”(http://www.voidtools.com/) 是一款非常棒的免费软件,但它缺少一个非常基本的功能,即“在当前路径内搜索”。目前,如果您想在 Windows 资源管理器中搜索当前打开的文件夹中的文件,例如“C:\Temp”,您必须手动转到“C:\”,然后选择 Temp 文件夹,右键单击它,选择“搜索所有内容”选项,完成所有这些操作后,您才能获得所需的内容。

有什么方法可以使这个重复的过程不那么痛苦吗?

答案1

我认为一定有更好的方法可以做到这一点。我发现此工具的创建者努力支持命令行选项,因此我编写了一个不错的 AutoHotkey 小脚本,它将第一段中描述的所有过程缩短为一个键盘快捷键。

非常重要的一点是,该脚本仅在 Windows7 x64 上进行了测试,所以我不能保证它可以在 Windows8、WindowsXP 等上运行。

该脚本显然需要在计算机上安装 AutoHotkey,并且必须在每次 Windows 启动时运行该脚本(因此最简单的方法是复制脚本的链接,或将整个脚本复制到 Autostart 文件夹中),以便它可以捕获键盘快捷键。快捷键设置为 Win+F,但可以在脚本中轻松修改。有一点要记住,脚本依赖于 Everything.exe 文件的路径,该文件位于此路径下:“C:\Program Files\Everything\Everything.exe”

如果它在其他地方,请修改该行。

在编写此脚本时,我使用以下脚本作为主干: https://superuser.com/a/205368/172360

这是我在网络上找到的唯一一个可以在我的机器上运行并返回路径的程序。我对它进行了一些调整,因为它不必要地使用了文字“地址”,并且它依赖于客户端操作系统中使用的本地语言,这带来了很大的限制,因此我用正则表达式替换它以在任何区域设置下工作(理论上 ;))。此外,路径必须以正确的方式格式化,所以我改变了它。之后,我添加了 SearchEverywhere 应用程序的相关代码,还添加了一些注释。

要“安装”脚本,您必须将其保存为带有 .ahk 扩展名的文本文件,然后运行它以便它可以驻留在后台。

至于用户体验,一旦您完成所有设置,您所要做的就是在 Windows 资源管理器处于焦点的情况下按下快捷键 (Win+F),然后 Search Everything 应用程序将启动,并在搜索框中自动输入相关路径。请记住,如果 Windows 中当前处于焦点的窗口不是资源管理器,则将发生默认的 Win+F(这是非常预期和期望的行为)。如果资源管理器的当前页面在“我的电脑”页面上打开,则此调用将被完全忽略。

它效果很好,我希望除了我之外,它还能对其他人有所帮助。尽情享受吧。

;////////////////////////////////////////////////////
;\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
;****************************************************
;*********                              *************
;*********    Written by:               *************
;*********                 soyo/Luk     *************
;*********                              *************
;********* Search everything: ver1_0_0  *************
;*********                              *************    
;****************************************************
;\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
;////////////////////////////////////////////////////

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


; 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
    {
    }
}

答案2

或这个:

 EverythingPath =  ;specify the path here

 #IfWinActive ahk_class CabinetWClass

  F6::
    folder := GetFolder()
    run, %EverythingPath% -path "%folder%"
  return

GetFolder(){
   WinGetClass,var,A
   If var in CabinetWClass,ExplorerWClass,Progman
    {
    IfEqual,var,Progman
        v := A_Desktop
    else
    {
        winGetText,Fullpath,A
        loop,parse,Fullpath,`r`n
        {
            IfInString,A_LoopField,:\
            {
                StringGetPos,pos,A_Loopfield,:\,L
                Stringtrimleft,v,A_loopfield,(pos - 1)
                break
            }
        }
    }
   return, v
  }
}

https://gist.github.com/aviaryan/5418603

相关内容