Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

-: Seek :- Launch program quickly & easily


  • Please log in to reply
19 replies to this topic

Poll: If you've tried Seek, do you: (30 member(s) have cast votes)

If you've tried Seek, do you:

  1. like it? (24 votes [77.42%])

    Percentage of vote: 77.42%

  2. neutral... (6 votes [19.35%])

    Percentage of vote: 19.35%

  3. hate it? (1 votes [3.23%])

    Percentage of vote: 3.23%

Vote Guests cannot vote
Phi
  • Members
  • 32 posts
  • Last active: Apr 19 2011 03:36 PM
  • Joined: 24 Sep 2004
Greetings to everyone. :)

Seek (v2.0.3 - updated 31st Jan 2005) is an AHK script that I've written for my own use, but I think others may be interested in it too. Here's the intro:

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.

Download the latest source code and the compiled .exe binary here.

Here's the change log since v2.0.2:

; * v2.0.3
; - Added /on option to DIR-command to sort by name.

; - Fuzzy search when user enters multiple query strings,
;   separated by space, for e.g. "med pla". It's a match
;   when all the strings ("med" & "pla") are found. This
;   will match "Media Player", "Macromedia Flash Player",
;   "Play Medieval King", "medpla", "plamed".

; - Corrected tab-movement sequence by adding all buttons
;   right from the start, but disable them until they can
;   be used.

; - Added status bar to replace tooltip-feedback.

; - Removed obsolete internal switch (ToolTipFilename).

; - Replaced the use of "dir" command with AutoHotkey's
;   own "Loop" command for scanning directory contents.
;   "dir" cannot handle extended character set and thus
;   non-English (e.g German) directory and filename are
;   captured wrongly. (Thanks Wolfgang Bujatti and
;   Sietse Fliege for testing this modification)

; - Added internal switch (ScanMode) to define whether
;   files and/or directories are to be included in scan.

; - Replaced hardcoded directory paths of Start Menu with
;   built-in variables A_StartMenu, A_StartMenuCommon.
;   With this, Seek now works for different locales with
;   different naming convention of the Start Menu.
;   (Thanks Wolfgang Bujatti and Sietse Fliege for help
;   in testing another method before these new variables
;   are available.)

; - Added the pre-selection of the last-run program
;   record so that a quick double-<ENTER> will run it.

Here's the source. Have fun! :lol:

; Seek -- by Phi
; http://www.autohotkey.com
; 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.

;*****************************************************************
;
;  Program : Seek
;  Coder   : Phi
;  Updated : Mon Jan 31 10:08:37 2005
;
;  What do you seek, my friend?
;
;*****************************************************************
;
;  I 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: phi1618 (*a.t*) gmail
;  :D0T: com.
;
;  Options:
;    -cache Use the cached directory-listing if available
;           (this is the default mode when no option is specified)
;    -scan  Force a directory scan to retrieve the latest
;           directory listing
;    -scex  Scan & exit (this is useful for scheduling the
;           potentially time-consuming directory-scanning as
;           a background job)
;    -help  Show this help
;
;*****************************************************************
;
; HOW TO 'SEEK':
;
; 1. 'Seek' is an AutoHotkey script. You can either run it
;    as Seek.ahk (original script) or Seek.exe (compiled
;    executable).
;
;    To obtain Seek.exe, you can download Seek.zip (includes
;    both the source code and the compiled binary) from
;    http://home.ripway.com/2004-10/188589/
;    Otherwise, you can compile Seek.ahk on your own by
;    using AutoHotkey's Ahk2Exe.exe compiler, or you can
;    ask me for a copy via email. The filesize is small at
;    about 200 kbytes. I can be reached at: phi1618 (*a.t*)
;    gmail :D0T: com.
;
;    To use Seek.ahk, first, you'll need to install
;    AutoHotkey v1.0.25 or higher on your PC (download from
;    http://www.autohotkey.com). Next, run the command:
;
;    X:\myTools\AutoHotkey\AutoHotkey.exe Y:\myAHK\Seek.ahk
;
;    Remember to replace X:\myTools and Y:\myAHK with
;    the proper directory names on your PC.
;
; 2. You can place the executable Seek.exe anywhere you
;    want. There is no installation required, it doesn't
;    write anything to your registry, and it doesn't
;    access the Internet at all (no phoning home). To
;    uninstall, simply delete Seek.exe.
;
;    The only 2 files 'Seek' creates are placed in your
;    TMP directory:
;
;      a. _Seek.key  (cache file for last query string)
;      b. _Seek.list (cache file for directory listing)
;
;    If you're a purist, you can delete them manually
;    when you decide to remove 'Seek' from your system.
;
; 3. The most convenient way to run 'Seek' is via a
;    shortcut/hotkey. If you are not already using any
;    hotkey management program on your PC, I highly
;    recommend AutoHotkey. If you don't intend to install
;    any hotkey management program at the moment, you can
;    make use of Windows shortcut feature and bind a
;    shortcut key (e.g. ALT-F1) to launch 'Seek'. This is
;    important so that you can run 'Seek' at anytime and
;    anywhere.
;
; 4. When you run 'Seek' for the first time, it'll scan
;    your Start Menu, and save the directory listing into
;    a cache file.
;
;    The following directories are included in the scanning:
;    - %A_StartMenu%
;    - %A_StartMenuCommon%
;
;    By default, subsequent runs will read from the
;    cache file so as to reduce the loading time. For
;    more info on options, run 'Seek.exe -help'. If you
;    think your Start Menu doesn't contain too many
;    programs, you can choose not to use the cache and
;    instruct 'Seek' to always do a directory scan (via
;    option -scan).  That way, you will always get the
;    latest listing.
;
; 5. When you run 'Seek', a window will appear, waiting
;    for you to enter a key word/phrase. After you have
;    entered a query string, a list of matching records
;    will be displayed. Next, you need to highlight an
;    entry and press <Enter> or click on the 'Open'
;    button to run the selected program or open the
;    selected directory.
;
;*****************************************************************
;
; TECHNICAL NOTES:
;
; - 'Seek' requires Chris Mallett's AutoHotkey v1.0.25
;   or higher version (http://www.autohotkey.com).
;   Thanks to Chris for his great work on AutoHotkey. :)
;
; - The following environment variables must be valid:
;   a. TMP
;
;*****************************************************************
;
; KNOWN PROBLEMS:
;
; - Nil
;
;*****************************************************************
;
; IMPLEMENTED SUGGESTIONS:
;
; - Highlight 1st matching record by default so that
;   user can just hit <Enter> to run it.
;   (Suggested by Yih Yeong)
;
; - Enable double-click on the listing of the search
;   results to launch the program.
;   (Suggested by Yih Yeong & Jack)
;
; - Auto real-time incremental search.
;   (Suggested by Rajat)
;
; - Fuzzy search when user enters multiple query strings,
;   separated by space.
;   (Suggested by Rajat)
;
;*****************************************************************
;
; SUGGESTED FEATURES (MAY OR MAY NOT BE IMPLEMENTED):
;
; - Log the launch history. List the most frequently
;   used programs at the top of the search results.
;   (Suggested by Yih Yeong)
;
; - Instead of using list box, can it display a series
;   of application icons so that hovering the cursor
;   over the icon will display a tooltip containing the
;   program information (path, etc).
;   (Suggested by Yih Yeong)
;
; - Instead of matching text in the middle, match only
;   those program/directory names that begin with the
;   query string.
;   (Suggested by Stefan)
;
; - Add favorites management. Launch group of programs
;   in a single run.
;   (Suggested by Atomhrt)
;
; - Integrate Seek into the Windows taskbar/toolbar so that
;   it is always available and there is no need to bind a
;   hotkey to launch Seek.
;   (Suggested by Deniz Akay)
;
; - Search by wildcards/regex.
;   (Suggested by Steve)
;
;*****************************************************************
;
; CHANGE HISTORY:
;
; * v1.1.0
; - Initial release.
;
; * v1.1.1
; - Removed maximise-window option since some programs don't
;   function well with it.
; - Added double-click detection to trigger 'Open' function.
;
; * v2.0.0
; - Integrated the 'Seek' popup window into the output screen
;   so that user can re-enter the query string to search for
;   something else without having to exit and run Seek again.
; - Added 'Scan Start-Menu' button.
; - Added real-time incremental search which will auto
;   filter for matching records while you type away,
;   without waiting for you to press <Enter>.
; - Added internal switch (TrackKeyPhrase) to track search-string.
; - Added internal switch (ToolTipFilename) to show filename
;   using tooltip.
;
; * v2.0.1
; - Added horizontal scrollbar to ListBox so that very
;   long records will not be cut-off in the middle.
;
; * v2.0.2
; - Allowed user to add their own customised list of directories
;   to be included in the scanning. User just needs to create a
;   text file 'Seek.dir' in the same directory as Seek.exe or
;   Seek.ahk, and specify the full path of the directory to be
;   added, one directory per line. Do not enclose the path in
;   quotes or double-quotes.
;
; * v2.0.3
; - Added /on option to DIR-command to sort by name.
; - Fuzzy search when user enters multiple query strings,
;   separated by space, for e.g. "med pla". It's a match
;   when all the strings ("med" & "pla") are found. This
;   will match "Media Player", "Macromedia Flash Player",
;   "Play Medieval King", "medpla", "plamed".
; - Corrected tab-movement sequence by adding all buttons
;   right from the start, but disable them until they can
;   be used.
; - Added status bar to replace tooltip-feedback.
; - Removed obsolete internal switch (ToolTipFilename).
; - Replaced the use of "dir" command with AutoHotkey's
;   own "Loop" command for scanning directory contents.
;   "dir" cannot handle extended character set and thus
;   non-English (e.g German) directory and filename are
;   captured wrongly. (Thanks Wolfgang Bujatti and
;   Sietse Fliege for testing this modification)
; - Added internal switch (ScanMode) to define whether
;   files and/or directories are to be included in scan.
; - Replaced hardcoded directory paths of Start Menu with
;   built-in variables A_StartMenu, A_StartMenuCommon.
;   With this, Seek now works for different locales with
;   different naming convention of the Start Menu.
;   (Thanks Wolfgang Bujatti and Sietse Fliege for help
;   in testing another method before these new variables
;   are available.)
; - Added the pre-selection of the last-run program
;   record so that a quick double-<ENTER> will run it.
;
;*****************************************************************

;**************************
;<--- BEGIN OF PROGRAM --->
;**************************

;==== Your Customisation ===================================

; Specify which program to use when opening a directory.
; If the program cannot be found or is not specified
; (i.e. variable is unassigned or assigned a null value),
; the default Explorer will be used.
dirExplorer = E:\utl\xplorer2_lite\xplorer2.exe

; User's customised list of additional directories to be
; included in the scanning. The full path must not be
; enclosed by quotes or double-quotes. If this file is
; missing, only the default directories will be scanned.
SeekMyDir = %A_ScriptDir%\Seek.dir

; Specify the filename and directory location to save
; the cached directory/program listing. There is no
; need to change this unless you want to.
dirListing = %tmp%\_Seek.list

; Specify the filename and directory location to save
; the cached key word/phrase of last search. There is
; no need to change this unless you want to.
keyPhrase = %tmp%\_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

;...........................................................

; INIT
;#NoTrayIcon
StringCaseSense, Off
version = Seek v2.0.3

; 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: phi1618 (*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, %TMP% ; PATH DOES NOT EXIST
{
	MsgBox This mandatory environment variable is either not defined or invalid:`n`n    TMP = %TMP%`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, 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 W764 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%

; 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 ...................................


;************************
;<--- END OF PROGRAM --->
;************************

; /* vim: set noexpandtab shiftwidth=4: */


Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
I think this is the most elaborately commented script I've ever seen. In addition, you've made it very simple to use. At first I was skeptical about its usefulness in my case, but after trying it I think it is definitely a time-saver, especially if you have hundreds of programs and utilities installed (despite my best attempts to organize the Start Menu, there are still times when I can't find something).

Since this script is so well documented and will probably have some appeal to at least 10% of site visitors, I'll add it to the script showcase if you wish.

BoBo
  • Guests
  • Last active:
  • Joined: --
Yep. I fully agree. A perfect sample how to provide a HowTo (aka comments if within a script).

Many thx & congrats 2 Phi.

8)

Phi
  • Members
  • 32 posts
  • Last active: Apr 19 2011 03:36 PM
  • Joined: 24 Sep 2004
Chris, do feel free to add it to your script showcase if you think it'll be helpful to the others. Thanks. :)

BoBo, thanks for the kind words too. :wink:

All suggestions/comments/feedback are welcome.

jack
  • Members
  • 75 posts
  • Last active: Oct 29 2010 08:33 PM
  • Joined: 04 Sep 2004
what a superb script!

the only thing that immediately springs to mind is that double-click would make it even better. however, i see you've thought of that and have been working on it.

thanks


jack

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
I have added this to the showcase (I know some other scripts are still waiting to be posted there. I haven't forgotten them.)

http://www.autohotke... ... eStartMenu).htm

Phi,
I edited the top slightly to make it conform to the HTML generator I use. I also tabified it to match the style of the other scripts and so that the generated HTML would preserve the formatting.

Finally, I removed the following lines because I don't want to give others the impression that they are necessary immediately prior to doing ExitApp (such cleanup is done automatically, which has now been documented in the help file):
Gui, 2:Cancel
Gui, 2:Destroy
Gui, 1:Cancel
Gui, 1:Destroy

If you want to make any changes, feel free to download the script (the .ahk file, not the .htm), apply the changes directly, and send me the new version.

Thanks for sharing this script,
Chris

Phi
  • Members
  • 32 posts
  • Last active: Apr 19 2011 03:36 PM
  • Joined: 24 Sep 2004
Jack, as you can see from the codes, I attempted to implement the launch-program-by-double-click feature by using timers. Somehow the 2nd-click cannot be detected, but the 3rd-click can. As a result, triple-click works, but that's highly unorthodox. :wink:

Initially, I wanted to allow the triple-click feature, but I found out that if the user tries to scroll down a very long list by holding down the Page-Down key, the triple-click detection will take place, and whichever program that is being highlighted at that time will be launched. This isn't right. So, I've commented out that part of the code. Currently, the only way to launch a program is by pressing , which is the same as clicking on the default 'Open' button.

If I can find another way to do this, or if the GUI codes are expanded to include double-click detection, I'll definitely change my codes to make double-click work. So meanwhile, hang in there. :lol:

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
Double-click detection should be released in the next update (sometime in the next couple of days).

Phi
  • Members
  • 32 posts
  • Last active: Apr 19 2011 03:36 PM
  • Joined: 24 Sep 2004
Chris,

Thanks for cleaning up the code. When the next version is ready, I'll send it to you. :)

By the way, in the course of writing this script, I notice that there isn't any direct command to check whether a path (e.g. c:\dir\xyz) is a file or a directory. I'm currently using FileReadLine as an alternative. If FileReadLine on c:\dir\xyz works, then it's a file, else a directory. But disk I/O is generally considered expensive operations, so I'll avoid it where possible.

Do you have any plan to add a new command that will do this simple check?

Cheers,
Phi.

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004

When the next version is ready, I'll send it to you.

Thanks. Please be sure to directly edit the showcase version so that tabs and other changes are retained (hopefully your text editor does not convert tabs to spaces).

I notice that there isn't any direct command to check whether a path (e.g. c:\dir\xyz) is a file or a directory

It's buried in the help file as FileGetAttrib

Rajat
  • Members
  • 1904 posts
  • Last active: Jul 17 2015 07:45 AM
  • Joined: 28 Mar 2004
i checked it out. its neat! and much much well commented than my code usually is.

here's a suggestion:
as the user types the keystrokes, the selectable closest matches (maybe just first 5 or something) be shown in realtime.

the following approaches might be used:
- settimer + controlgettext
- input cmd in a loop taking just one char (i used it in intellisense script)

MIA

CleanNews.in : Bite sized latest news headlines from India with zero bloat


Phi
  • Members
  • 32 posts
  • Last active: Apr 19 2011 03:36 PM
  • Joined: 24 Sep 2004
Greetings.

Seek v2.0.0 is out. It's a major update. Please refer to the 1st post for the change log and source code.

Jack, double-click works like a charm now. :)

Rajat, I've implemented your suggestion for real-time incremental search. I like it very much. Thanks for the suggestion. :)

Chris, I've changed file/directory detection to use FileGetAttrib. Code is cleaner now. :) And, don't worry about the tabs to spaces conversion because I've instructed Vim not to do so specifically for this script. My personal preference for indentation is still space though. That way, it looks the same no matter what text editor is used for viewing. :)

Oh btw, Chris, any chance of adding a horizontal scroll bar to a listbox? Currently, the very long records in my listbox are cut-off in the middle, and user can't see what's on the right because the listbox doesn't have a horizontal scrollbar.

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004

any chance of adding a horizontal scroll bar to a listbox?

Thanks for mentioning it. It turns out that you need to add two things to get a horizontal scroll bar:

1) The word HScroll in the ListBox's "Gui Add" options.

2) After the window is shown for the first time, send this message to it:

; Replace the number 500 with the desired scrollable width:
SendMessage, 0x194, 500, 0, ListBox1, MyWinTitle ; 0x194 is LB_SETHORIZONTALEXTENT

You could also send the message before the window is shown if you do "DetectHiddenWindows on".

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
I've updated the installer so that the above SendMessage is not necessary. Instead, you can specify just HScroll to get a scrolling width equal to 3 times the visible width of the ListBox. You can also specify something like HScroll500 to get 500 pixels worth of scrolling width.

Phi
  • Members
  • 32 posts
  • Last active: Apr 19 2011 03:36 PM
  • Joined: 24 Sep 2004
Thanks for the instructions and updating the installer. I've added the horizontal scrollbar.