I have optimized the script, thanks to the help of mikeyww viewtopic.php?f=76&t=111854 and Void https://www.voidtools.com/forum/viewtopic.php? p=51625#p51625 and I have added more symbols that can hinder the search —when part of the file name is closed with () or []—.
In the preferences of the "Everything" program, activate the "Espand environment variables" box, in the "Search" section, as shown in the image.
Code: Select all
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory
;EnvSet, SD, %A_ScriptDir%
;^!F8:: ; If a keyboard shortcut is used, all lines with the "ExitApp" command must be replaced by the "Return" command, except the last line.
GetKeyState, state, Ctrl
if (state = "D") ; Hold down the "Ctrl" key if you want to clear the clipboard and pop up the search window.
{
ClipBoard:=""
}
Send ^c ; You only need to select the search text.
OutFile = h:\File_Temp.txt ;Change the output file path if necessary. This file is not deleted until the next search.
App = d:\Utilidades\Everything\es.exe ;Change the path of the "Everything.exe" program if necessary.
DetectHiddenWindows, Off
if not WinExist("Everything")
{
Run, d:\Utilidades\Everything\Everything.exe -startup
}
If !Clipboard
{
Gosub, SearchGUI
}
Else
{
TempClip:= Clipboard
Gosub, Rutine
}
Return
SearchGUI:
TempClip:=Clipboard
xposSearch:= Floor((A_ScreenWidth/2)-450)
yposSearch:= Floor((A_ScreenHeight/2)-200)
Gui, Search:+HwndGuiID
Gui, Search: Font, S9 Bold, Verdana
Gui, Search: Add, Edit, x10 y16 w230 h20 vMySearch, Enter your Search
Gui, Search: Add, Button, x250 y16 w65 h20 GSearch, Search
Gui, Search: Add, CheckBox, x10 y46 w300 h20 vRegEx, Use RegEx Search
Gui, Search: Show, x%xposSearch% y%yposSearch% h80 w330, GUI
Return
#If WinActive("ahk_id " GuiID)
Enter::
NumPadEnter::
Search:
Gui Search: Submit
TempClip:=MySearch
Gui Search: Destroy
Gosub, Rutine
Return
Rutine:
FileDelete, %OutFile%
If RegEx=1
{
RunWait, "%App%" -export-txt "%OutFile%" -r "%TempClip%",, Hide
}
Else
{
TempClip:= RegexReplace(TempClip, "[\[\]()\-\_\s+]", "*") ;Subtract or add symbols within this replacement line of the text to find. Now replace the symbols: -_[]() and space with a wildcard.
RunWait, "%App%" -export-txt "%OutFile%" "%TempClip%",, Hide
}
FileRead, OutputEnd, %OutFile%
If !OutputEnd
{
Gosub, NotFound
}
Else
{
Gosub, GuiControl
}
Return
GuiControl:
Loop, Read, %OutFile%
NumLines := A_Index
SoundPlay, *64
xposControl:= Floor((A_ScreenWidth/2)-450)
yposControl:= Floor((A_ScreenHeight/2)-200)
Gui, Control: Add, GroupBox, x22 y60 w340 h140, Options
Gui, Control: Add, Radio, x32 y80 w300 h20 vDirectory, Open the Container Directory
Gui, Control: Add, Radio, x32 y100 w300 h20 vOpenFile, Open the file
Gui, Control: Add, Radio, x32 y120 w300 h20 vFileAndDir, Open the File and Open the Directory
Gui, Control: Add, Radio, x32 y140 w300 h20 vNothing Checked, Do Nothing
Gui, Control: Add, CheckBox, x32 y170 w100 h20 vCopyClip, Copy to Clipboard
Gui, Control: Add, CheckBox, x150 y170 w100 h20 vTxtOpen, Open file List
Gui, Control: Add, Button, x30 y210 w100 h30 gCancel, Cancel
Gui, Control: Add, Button, x252 y210 w100 h30 gOptions, OK
Gui, Control: Add, Text, x22 y16 w340 h40 , %NumLines% file(s) exists in %OutputEnd%
Gui, Control: Show,x%xposControl% y%yposControl% h260 w384, GUI Control
Return
Options:
Gui, Control: Submit
If Directory
{
If (NumLines<>1)
{
Loop, %NumLines%
{
FileReadLine, VarOut, %OutFile%, %A_Index%
StringGetPos, pos, VarOut, \, r1
length := pos+1
StringLeft, OutText, VarOut, %length%
Run, explorer %OutText%
}
}
Else
{
StringGetPos, pos, OutputEnd, \, r1
length := pos+1
StringLeft, OutText, OutputEnd, %length%
Run, explorer %OutText%
}
If CopyClip=1
{
Clipboard:= OutputEnd
}
If TxtOpen=1
{
Run, %OutFile%
}
ExitApp
}
If OpenFile
{
If (NumLines<>1)
{
Loop, %NumLines%
{
FileReadLine, VarOut, %OutFile%, %A_Index%
Run, Explorer %VarOut%
}
}
Else
{
Run, Explorer %OutputEnd%
}
If CopyClip=1
{
Clipboard:= OutputEnd
}
If TxtOpen=1
{
Run, %OutFile%
}
ExitApp
}
If FileAndDir
{
If (NumLines<>1)
{
Loop, %NumLines%
{
FileReadLine, VarOut, %OutFile%, %A_Index%
Run, Explorer %VarOut%
StringGetPos, pos, VarOut, \, r1
length := pos+1
StringLeft, OutText, VarOut, %length%
Run, Explorer %OutText%
}
}
Else
{
Run, Explorer %OutputEnd%
StringGetPos, pos, OutputEnd, \, r1
length := pos+1
StringLeft, OutText, OutputEnd, %length%
Run, explorer %OutText%
}
If CopyClip=1
{
Clipboard:= OutputEnd
}
If TxtOpen=1
{
Run, %OutFile%
}
ExitApp
}
If Nothing
If CopyClip=1
{
Clipboard:= OutputEnd
}
If TxtOpen=1
{
Run, %OutFile%
}
ExitApp
NotFound:
SoundPlay, *64
MsgBox, The file does not exist on the computer.
ExitApp
Cancel:
ExitApp