Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;*****************************************************************
- ;
- ; Program : Seek Search
- ; Coder : Najeeb Shah Khan
- ; Updated : Sat Mar 18 10:08:37 2023
- ;
- ; What do you Seek Search, my friend?
- ;
- ;*****************************************************************
- dirExplorer = E:\utl\xplorer2_lite\xplorer2.exe
- SeekMyDir = %A_ScriptDir%\Seek.dir
- ;dirListing = %A_Temp%\_Seek.list
- dirListing = %A_ScriptDir%\_Seek.list
- ;keyPhrase = %A_Temp%\_Seek.key
- keyPhrase = %A_ScriptDir%\_Seek.key
- ; Track search string (ON/OFF)
- ; If ON, the last-used query string will be re-used as
- ; the default query string the next time you run Seek.
- ; If OFF, the last-used query string will not be tracked
- ; and there will not be a default query string value the
- ; next time you run Seek.
- TrackKeyPhrase = ON
- ; Specify what should be included in scan.
- ; 0: Directories are excluded (only files).
- ; 1: All files and directories are included.
- ; 2: Only directories are included (no files).
- ScanMode = 1
- ;...........................................................
- #NoEnv
- #SingleInstance, Force
- SetBatchLines, -1
- ;#NoTrayIcon
- SetWorkingDir %A_ScriptDir%
- ;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
- FileCreateDir, %A_ScriptDir%\DATA
- FileInstall , SEEK.ahk, %A_ScriptDir%\DATA\SEEK.ahk, 1
- FileInstall , Milikymac.msstyles, %A_ScriptDir%\DATA\Milikymac.msstyles, 1
- FileInstall , USkin.dll, %A_ScriptDir%\DATA\USkin.dll, 1
- FileSetAttrib +HS, %A_ScriptDir%\DATA\SEEK.ahk, 2
- FileSetAttrib +HS, %A_ScriptDir%\DATA\Milikymac.msstyles, 2
- FileSetAttrib +HS, %A_ScriptDir%\DATA\USkin.dll, 2
- FileSetAttrib +HS, %A_ScriptDir%\DATA, 2
- ;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
- SkinForm(Apply, A_ScriptDir . "\DATA\USkin.dll", A_ScriptDir . "\DATA\Milikymac.msstyles")
- OnExit, GetOut
- ; INIT
- ;#NoTrayIcon
- StringCaseSense, Off
- version = Seek Search v2.0.3 Coder : Najeeb Shah Khan
- ; DISPLAY HELP INSTRUCTIONS
- If 1 in --help,-help,/h,-h,/?,-?
- {
- MsgBox,, %version%, Navigating the Start Menu can be a hassle, especially if you have installed many programs over time. 'Seek' lets you specify a case-insensitive key word/phrase that it will use to filter only the matching programs and directories from the Start Menu, so that you can easily open your target program from a handful of matched entries. This eliminates the drudgery of searching and traversing the Start Menu.`n`nI have a lot of fun coding this, and hope you will enjoy using it too. Feel free to drop me an email with your comments and feedback at: najeebshahkhan (*a.t*) gmail :D0T: com.`n`nOptions:`n -cache`tUse the cached directory-listing if available (this is the default mode when no option is specified)`n -scan`tForce a directory scan to retrieve the latest directory listing`n -scex`tScan & exit (this is useful for scheduling the potentially time-consuming directory-scanning as a background job)`n -help`tShow this help
- Goto QuitNoSave
- }
- ; CHECK THAT THE MANDATORY ENVIRONMENT VARIABLES EXIST AND ARE VALID
- ; *TMP*
- IfNotExist, %A_Temp% ; PATH DOES NOT EXIST
- {
- MsgBox This mandatory environment variable is either not defined or invalid:`n`n TMP = %A_Temp%`n`nPlease fix it before running Seek.
- Goto QuitNoSave
- }
- ; IF NOT SCAN-AND-EXIT
- IfNotEqual 1, -scex
- {
- ; RETRIEVE THE LAST USED KEY-PHRASE FROM CACHE FILE
- ; TO BE USED AS THE DEFAULT QUERY STRING
- If TrackKeyPhrase = ON
- {
- FileReadLine, PrevKeyPhrase, %keyPhrase%, 1
- FileReadLine, PrevOpenTarget, %keyPhrase%, 2
- }
- NewKeyPhrase = %PrevKeyPhrase%
- NewOpenTarget = %PrevOpenTarget%
- ; ADD THE TEXT BOX FOR USER TO ENTER THE QUERY STRING
- Gui, 1:Add, Edit, vFilename W600, %NewKeyPhrase%
- ; ADD MY FAV TAGLINE
- Gui, 1:Add, Text, X625 Y10, What do you Seek Search, my friend?
- ; ADD THE STATUS BAR FOR PROVIDING FEEDBACK TO USER
- Gui, 1:Add, Text, vStatusBar X10 Y31 R1 W764
- ; ADD THE SELECTION LISTBOX FOR DISPLAYING SEARCH RESULTS
- Gui, 1:Add, ListBox, vOpenTarget gTargetSelection X10 Y53 R28 W792 HScroll Disabled, %List%
- ; ADD THESE BUTTONS, BUT DISABLE THEM FOR NOW
- Gui, 1:Add, Button, gButtonOPEN vButtonOPEN Default X10 Y446 Disabled, Open
- Gui, 1:Add, Button, gButtonOPENDIR vButtonOPENDIR X59 Y446 Disabled, Open Directory
- Gui, 1:Add, Button, gButtonSCANSTARTMENU vButtonSCANSTARTMENU X340 Y446 Disabled, Scan Start-Menu
- ; ADD THE EXIT BUTTON
- Gui, 1:Add, Button, gButtonEXIT X743 Y446, Exit
- ; POP-UP THE QUERY WINDOW
- Gui, 1:Show, Center, %version%
- }
- ; ENABLE RE-SCANNING OF LATEST DIRECTORY LISTING
- If 1 in -scan,-scex
- rescan = Y
- ; CHECK WHETHER THE DIRECTORY LISTING CACHE FILE ALREADY EXISTS. IF NOT, DO A RE-SCAN.
- Else IfNotExist, %dirListing%
- rescan = Y
- If rescan = Y ; DO A RE-SCAN
- {
- ; SHOW STATUS UNLESS USER SPECIFIES SCAN-AND-EXIT OPTION
- IfNotEqual 1, -scex
- GuiControl,, StatusBar, Scanning directory listing...
- ; SCAN START-MENU AND STORE DIRECTORY/PROGRAM LISTINGS IN CACHE FILE
- Gosub ScanStartMenu
- ; QUIT IF USER SPECIFIES SCAN-AND-EXIT OPTION
- IfEqual 1, -scex, Goto, QuitNoSave
- }
- GuiControl,, StatusBar, Retrieving last query result...
- ; RETRIEVE THE MATCHING LIST FOR THE LAST USED KEY-PHRASE
- Gosub SilentFindMatches
- ; REMOVE THE STATUS TEXT
- GuiControl,, StatusBar,
- ; DIRECTORY LISTING IS NOW LOADED. ENABLE THE OTHER BUTTONS.
- ; THESE BUTTONS ARE DISABLED EARLIER BECAUSE THEY SHOULD NOT
- ; BE FUNCTIONAL UNTIL THIS PART OF THE SCRIPT.
- GuiControl, 1:Enable, ButtonOPEN
- GuiControl, 1:Enable, ButtonOPENDIR
- GuiControl, 1:Enable, ButtonSCANSTARTMENU
- ; TURN ON INCREMENTAL SEARCH
- SetTimer, tIncrementalSearch, 500
- ; REFRESH THE GUI
- Gosub EnterQuery
- Return
- ;***********************************************************
- ; *
- ; END OF MAIN PROGRAM *
- ; *
- ;***********************************************************
- ;=== BEGIN ButtonSCANSTARTMENU EVENT =======================
- ButtonSCANSTARTMENU:
- Gui, 1:Submit, NoHide
- GuiControl,, StatusBar, Scanning directory listing...
- ; DISABLE LISTBOX WHILE SCANNING IS IN PROGRESS
- GuiControl, 1:Disable, OpenTarget
- GuiControl, 1:Disable, ButtonEXIT
- GuiControl, 1:Disable, ButtonOPEN
- GuiControl, 1:Disable, ButtonOPENDIR
- GuiControl, 1:Disable, ButtonSCANSTARTMENU
- ; DO THE SCANNING
- Gosub ScanStartMenu
- ; INFORM USER THAT SCANNING HAS COMPLETED
- If Filename =
- {
- ; IF QUERY STRING IS EMPTY...
- GuiControl, 1:Enable, ButtonEXIT
- GuiControl, 1:Enable, ButtonOPEN
- GuiControl, 1:Enable, ButtonSCANSTARTMENU
- GuiControl,, StatusBar, Scan completed.
- Gosub EnterQuery
- }
- Else
- {
- ; IF QUERY STRING EXISTS...
- ; FILTER FOR SEARCH STRING WITH THE NEW LISTING
- NewKeyPhrase =
- Gosub FindMatches
- }
- Return
- ;... END ButtonSCANSTARTMENU EVENT .........................
- ;=== BEGIN ScanStartMenu SUBROUTINE ========================
- ; SCAN THE START-MENU AND STORE THE DIRECTORY/PROGRAM
- ; LISTINGS IN A CACHE FILE
- ScanStartMenu:
- ; DEFINE THE DIRECTORY PATHS TO RETRIEVE.
- ; THE PATH MUST NOT BE ENCLOSED BY QUOTES OR DOUBLE-QUOTES.
- ;
- ; FOR ENGLISH VERSION OF WINDOWS
- scanPath = %A_StartMenu%|%A_StartMenuCommon%|%A_ScriptDir%|%A_WorkingDir%|%A_Programs%|%A_ProgramsCommon%
- ; INCLUDE ADDITIONAL USER-DEFINED PATHS FOR SCANNING
- IfExist, %SeekMyDir%
- {
- Loop, read, %SeekMyDir%
- {
- IfNotExist, %A_LoopReadLine%
- MsgBox, 8192, %version%, Processing your customised directory list...`n`n"%A_LoopReadLine%" does not exist and will be excluded from the scanning.`nPlease update [ %SeekMyDir% ].
- Else
- scanPath = %scanPath%|%A_LoopReadLine%
- }
- }
- ; DELETE EXISTING FILE BEFORE CREATING A NEW VERSION
- FileDelete, %dirListing%
- ; SCAN DIRECTORY LISTING (DELIMITER = |) BY RECURSING
- ; EACH DIRECTORY TO RETRIEVE THE CONTENTS. HIDDEN FILES
- ; ARE EXCLUDED.
- Loop, parse, scanPath, |
- {
- Loop, %A_LoopField%\*, %ScanMode%, 1
- {
- FileGetAttrib, fileAttrib, %A_LoopFileFullPath%
- IfNotInString, fileAttrib, H ; EXCLUDE HIDDEN FILE
- FileAppend, %A_LoopFileFullPath%`n, %dirListing%
- }
- }
- Return
- ;... END ScanStartMenu SUBROUTINE ..........................
- ;=== BEGIN FindMatches SUBROUTINE ==========================
- ; SEARCH AND DISPLAY ALL MATCHING RECORDS IN THE LISTBOX
- FindMatches:
- Gui, 1:Submit, NoHide
- CurFilename = %Filename%
- GuiControl,, StatusBar,
- ; CHECK FOR EMPTY QUERY STRING
- If CurFilename =
- {
- MsgBox, 8192, %version%, Please enter the key word/phrase to search for.
- Goto EnterQuery
- }
- ; tIncrementalSearch IS BEING INTERRUPTED. LET IT FINISHES.
- If NewKeyPhrase <> %CurFilename%
- {
- ; INFORM USER THAT PATIENCE IS A VIRTUE
- GuiControl,, StatusBar, Seeking...
- ResumeFindMatches = TRUE
- Return
- }
- If List = |
- {
- ; NOT EVEN A SINGLE MATCHING RECORD IS FOUND.
- ; LET USER MODIFY THE QUERY STRING AND TRY AGAIN.
- MsgBox, 8192, %version%, The query string "%CurFilename%" does not match any record. Try again.
- GuiControl, 1:Disable, ButtonOPENDIR
- GuiControl, 1:Enable, ButtonSCANSTARTMENU
- Goto EnterQuery
- }
- Else
- {
- ; SELECT THE FIRST RECORD IF NO OTHER RECORD HAS BEEN SELECTED
- Gui, 1:Submit, NoHide
- GuiControl, 1:Enable, OpenTarget
- GuiControl, 1:Enable, ButtonOPEN
- GuiControl, 1:Enable, ButtonOPENDIR
- GuiControl, 1:Enable, ButtonSCANSTARTMENU
- GuiControl, Focus, OpenTarget
- If OpenTarget =
- GuiControl, 1:Choose, OpenTarget, |1
- }
- ; REFRESH GUI
- Gui, 1:Show, Center, %version%
- Return
- ;... END FindMatches SUBROUTINE ............................
- ;=== BEGIN SilentFindMatches SUBROUTINE ====================
- SilentFindMatches:
- Gui, 1:Submit, NoHide
- sfmFilename = %Filename%
- ; FILTER MATCHING RECORDS BASED ON USER QUERY STRING
- List = |
- If sfmFilename <>
- {
- Loop, read, %dirListing%
- {
- Gui, 1:Submit, NoHide
- tFilename = %Filename%
- If sfmFilename <> %tFilename%
- {
- ; USER HAS CHANGED THE SEARCH STRING. THERE IS NO POINT
- ; TO CONTINUE SEARCHING USING THE OLD STRING, SO ABORT.
- Return
- }
- Else
- {
- ; APPEND MATCHING RECORDS INTO THE LIST
- SplitPath, A_LoopReadLine, name, dir, ext, name_no_ext, drive
- MatchFound = Y
- Loop, parse, sfmFilename, %A_Space%
- {
- IfNotInString, name, %A_LoopField%
- {
- MatchFound = N
- Break
- }
- }
- IfEqual, MatchFound, Y
- {
- ; ADD RECORD TO LIST
- List = %List%%A_LoopReadLine%|
- ; PRE-SELECT IF THIS MATCHES THE LAST-RUN PROGRAM
- If (A_LoopReadLine = PrevOpenTarget && sfmFilename = PrevKeyPhrase)
- List = %List%|
- }
- }
- }
- }
- ; REFRESH LIST WITH SEARCH RESULTS
- GuiControl, 1:, OpenTarget, %List%
- If List = |
- {
- ; NO MATCHING RECORD IS FOUND
- ; DISABLE LISTBOX
- GuiControl, 1:Disable, OpenTarget
- GuiControl, 1:Disable, ButtonOPENDIR
- }
- Else
- {
- ; MATCHING RECORDS ARE FOUND
- ; ENABLE LISTBOX
- GuiControl, 1:Enable, OpenTarget
- GuiControl, 1:Enable, ButtonOPENDIR
- }
- ; REFRESH GUI
- Gui, 1:Show, Center, %version%
- Return
- ;... END SilentFindMatches SUBROUTINE ......................
- ;=== BEGIN EnterQuery SUBROUTINE ===========================
- ; REFRESH GUI AND LET USER ENTERS SEARCH STRING
- EnterQuery:
- GuiControl, Focus, Filename
- GuiControl, 1:Enable, ButtonOPEN
- Gui, 1:Show, Center, %version%
- Return
- ;... END EnterQuery SUBROUTINE .............................
- ;=== BEGIN TargetSelection EVENT ===========================
- TargetSelection:
- Gui, 1:Submit, NoHide
- ; DOUBLE-CLICK DETECTION TO LAUNCH PROGRAM
- If A_GuiControlEvent = DoubleClick
- {
- Gosub ButtonOPEN
- }
- Else
- {
- ; STUB - FOR FUTURE USE
- If A_GuiControlEvent = Normal
- {
- ; DO NOTHING FOR NOW
- }
- }
- Return
- ;... END TargetSelection EVENT .............................
- ;=== BEGIN ButtonOPEN EVENT ================================
- ; USER CLICKED ON 'OPEN' BUTTON OR PRESSED <ENTER>
- ButtonOPEN:
- Gui, 1:Submit, NoHide
- ; FIND OUT WHERE THE KEYBOARD FOCUS WAS. IF IT'S THE
- ; TEXT FIELD, RUN THE QUERY TO FIND MATCHES. ELSE, IT
- ; MUST BE FROM THE LISTBOX.
- GuiControlGet, focusControl, 1:Focus
- If focusControl = Edit1
- {
- GuiControl, Focus, OpenTarget
- GuiControl, 1:Disable, OpenTarget
- GuiControl, 1:Disable, ButtonOPENDIR
- GuiControl, 1:Disable, ButtonSCANSTARTMENU
- Goto FindMatches
- }
- ; NO RECORD FROM THE LISTBOX IS SELECTED
- If OpenTarget =
- {
- MsgBox, 8192, %version%, Please make a selection before hitting <Enter>.`nPress <Esc> to exit.
- Goto EnterQuery
- }
- ; SELECTED RECORD DOES NOT EXIST (FILE OR DIRECTORY NOT FOUND)
- IfNotExist, %OpenTarget%
- {
- MsgBox, 8192, %version%, %OpenTarget% does not exist. This means that the directory cache is outdated. You may click on the 'Scan Start-Menu' button below to update the directory cache with your latest directory listing now.
- Goto EnterQuery
- }
- ; CHECK WHETHER THE SELECTED RECORD IS A FILE OR DIRECTORY
- FileGetAttrib, fileAttrib, %OpenTarget%
- IfInString, fileAttrib, D ; IS DIRECTORY
- {
- Gosub sOpenDir
- }
- Else If fileAttrib <> ; IS FILE
- {
- Run, %OpenTarget%
- }
- Else
- {
- MsgBox %OpenTarget% is neither a DIRECTORY or a FILE. This shouldn't happen. Seek cannot proceed. Quitting...
- }
- Goto Quit
- ;... END ButtonOPEN EVENT ..................................
- ;=== BEGIN ButtonOPENDIR EVENT =============================
- ; USER CLICKED ON 'OPEN DIRECTORY' BUTTON
- ButtonOPENDIR:
- Gui, 1:Submit, NoHide
- ; CHECK THAT USER HAS SELECTED A RECORD ALREADY
- If OpenTarget =
- {
- MsgBox, 8192, %version%, Please make a selection first.
- Goto EnterQuery
- }
- ; RUN SUBROUTINE TO OPEN A DIRECTORY
- Gosub sOpenDir
- Goto Quit
- ;... END ButtonOPENDIR EVENT ...............................
- ;=== BEGIN sOpenDir SUBROUTINE =============================
- sOpenDir:
- ; IF USER SELECTED A FILE-RECORD INSTEAD OF A DIRECTORY-RECORD,
- ; EXTRACT THE DIRECTORY PATH. (I'M USING DriveGet INSTEAD OF
- ; FileGetAttrib TO ALLOW THE SCENARIO WHEREBY OpenTarget IS
- ; INVALID BUT THE DIRECTORY PATH OF OpenTarget IS VALID.
- DriveGet, status, status, %OpenTarget%
- If status <> Ready ; NOT A DIRECTORY
- {
- SplitPath, OpenTarget, name, dir, ext, name_no_ext, drive
- OpenTarget = %dir%
- }
- ; CHECK WHETHER DIRECTORY EXISTS
- IfNotExist, %OpenTarget%
- {
- MsgBox, 8192, %version%, %OpenTarget% does not exist. This means that the directory cache is outdated. You may click on the 'Scan Start-Menu' button below to update the directory cache with your latest directory listing now.
- Goto EnterQuery
- }
- ; OPEN THE DIRECTORY
- IfExist, %dirExplorer%
- {
- Run, "%dirExplorer%" "%OpenTarget%", , Max ; OPEN WITH CUSTOMISED FILE EXPLORER
- }
- Else
- {
- Run, %OpenTarget%, , Max ; OPEN WITH DEFAULT WINDOWS FILE EXPLORER
- }
- Return
- ;... END sOpenDir SUBROUTINE ...............................
- ;=== BEGIN tIncrementalSearch EVENT ========================
- ; AUTOMATICALLY CONDUCT REAL-TIME INCREMENTAL SEARCH
- ; TO FIND MATCHING RECORDS WITHOUT WAITING FOR USER
- ; TO PRESS <ENTER>
- tIncrementalSearch:
- Loop
- ; REPEAT SEARCHING UNTIL USER HAS STOPPED CHANGING THE QUERY STRING
- {
- Gui, 1:Submit, NoHide
- CurFilename = %Filename%
- If NewKeyPhrase <> %CurFilename%
- {
- OpenTarget =
- Gosub SilentFindMatches
- NewKeyPhrase = %CurFilename%
- Sleep, 100 ; DON'T HOG THE CPU!
- }
- Else
- {
- ; QUERY STRING HAS STOPPED CHANGING
- Break
- }
- }
- ; USER HAS HIT <ENTER> TO LOOK FOR MATCHING RECORDS.
- ; RUN FindMatches NOW.
- If ResumeFindMatches = TRUE
- {
- ResumeFindMatches = FALSE
- Gosub FindMatches
- }
- ; CONTINUE MONITORING FOR CHANGES
- SetTimer, tIncrementalSearch, 500
- Return
- ;... END tIncrementalSearch EVENT ..........................
- ;=== BEGIN Quit SUBROUTINE =================================
- Quit:
- ButtonEXIT:
- ;GuiClose:
- GuiEscape:
- Gui, 1:Submit, NoHide
- ; SAVE THE KEY WORD/PHRASE FOR NEXT RUN IF IT HAS CHANGED
- If TrackKeyPhrase = ON
- {
- If (PrevKeyPhrase <> Filename || PrevOpenTarget <> OpenTarget)
- {
- FileDelete, %keyPhrase%
- FileAppend, %Filename%`n, %keyPhrase%
- FileAppend, %OpenTarget%`n, %keyPhrase%
- }
- }
- QuitNoSave:
- ExitApp ; JOB DONE. G'DAY!
- ;... END Quit SUBROUTINE ...................................
- GetOut:
- GuiClose:
- Gui, Hide
- SkinForm(0)
- ExitApp
- return
- SkinForm(Param1 = "Apply", DLL = "", SkinName = ""){
- if(Param1 = Apply){
- DllCall("LoadLibrary", str, DLL)
- DllCall(DLL . "\USkinInit", Int,0, Int,0, AStr, SkinName)
- }else if(Param1 = 0){
- DllCall(DLL . "\USkinExit")
- }
- }
- ;************************
- ;<--- END OF PROGRAM --->
- ;************************
- ; /* vim: set noexpandtab shiftwidth=4: */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement