Using FileSelectFolder for Windows File Explorer AutoHotkey Menus

For Precise Selection of Windows Folders When Loading Files into a Launching Menu, Use the AutoHotkey FileSelectFolder Command

Last time, I mentioned the possibility of using the FileSelectFile command to pick the top-level folder when adding files to an AutoHotkey action menu using the barebones FileMenuLoad.ahk script. Upon further consideration, I realized that the FileSelectFolder command offered a more appropriate solution. Accidentally picking a file rather than a folder for the top-level—although workable—only introduces more complications. The FileSelectFolder command precludes the inadvertent selection of a file.

You can insert the command at the beginning of the script as follows:

^#!m::

FileSelectFolder, TopMenu, *C:\Users\%A_UserName%\QuickLinks

If errorlevel
	Return

LastMenu := TopMenu

Loop Files, %TopMenu%\*.*, DFR  ; Recurse into subfolders.
{
	; Skip any file that is H or S (System).
	If InStr(A_LoopFileAttrib, "H") or InStr(A_LoopFileAttrib, "S") 
		Continue
	; Add to Menu	
	Menu, %A_LoopFileDir%, Add, %A_LoopFileName% , Action
	If (A_LoopFileDir != LastMenu) and (LastMenu != TopMenu)
	{
;		MsgBox %TopMenu% %LastMenu%
		AddMenu(LastMenu)
	}
	; Save menu name
	LastMenu := A_LoopFileDir
}

AddMenu(LastMenu)

Menu, %TopMenu%, Show

Return


Action:

Run, % A_ThisMenu . "\" . A_ThisMenuItem

Return

AddMenu(MenuName)
{
	SplitPath, MenuName , DirName, OutDir, OutExtension, OutNameNoExt, OutDrive
	Menu, %OutDir%, Add, %DirName%, :%MenuName%
}

While the FileSelectFolder command works well enough, whether or not you use it depends upon what you want to accomplish. In most cases, you may find it easier to hardcode the target folder into your script.

I don’t think I would use this folder selection command to randomly search through the Window File Explorer structure looking for folders/subfolders to cram into a menu. The command works best when you use folders set up in a way that a menu makes natural sense (such a QuickLinks). Possibly, you have a number of folders grouped together for QuickLinks type action, but only want to make the selection at runtime.

Special Folder Starting Points

The FileSelectFolder command offers special codes for loading specific Windows folders:

FileSelectFolder, TopMenu, ::{20d04fe0-3aea-1069-a2d8-08002b30309d} , 0 ; My Computer
FileSelectFolder, TopMenu, ::{450d8fba-ad25-11d0-98a8-0800361b1103} , 0 ; My Documents
FileSelectFolder, TopMenu, ::{48e7caab-b918-4e58-a94d-505519c795dc}, 0 ; Start Menu Folder 

You can find these in the Windows Class Identifier List. This allows you to specify a standard starting location without entering the full path.

Tip: In order to activate roaming in higher-level folders, place an asterisk ( * ) in front of the default path:

FileSelectFolder, TopMenu, *::{20d04fe0-3aea-1069-a2d8-08002b30309d}, 0 ; My Computer
FileSelectFolder, TopMenu, *::{450d8fba-ad25-11d0-98a8-0800361b1103}, 0 ; My Documents
FileSelectFolder, TopMenu, *::{48e7caab-b918-4e58-a94d-505519c795dc}, 0 ; Start Menu Folder 

Play with the options to decide what works best for you.

Click the Follow button at the top of the sidebar on the right of this page for e-mail notification of new blogs. (If you’re reading this on a tablet or your phone, then you must scroll all the way to the end of the blog—pass any comments—to find the Follow button.)

jack

This post was proofread by Grammarly
(Any other mistakes are all mine.)

(Full disclosure: If you sign up for a free Grammarly account, I get 20¢. I use the spelling/grammar checking service all the time, but, then again, I write a lot more than most people. I recommend Grammarly because it works and it’s free.)

Find my AutoHotkey books at ComputorEdge E-Books!

Find quick-start AutoHotkey classes at “Robotic Desktop Automation with AutoHotkey“!

One thought on “Using FileSelectFolder for Windows File Explorer AutoHotkey Menus

  1. Hi Jacks. This is not related with this topic but the Dictionary.ahk. I guess i found a solution. It looks like an update issue. If you are still interested in Check these links:https://support.microsoft.com/en-us/topic/update-to-enable-tls-1-1-and-tls-1-2-as-default-secure-protocols-in-winhttp-in-windows-c4bd73d2-31d7-761e-0178-11268bb10392

    https://es.coredump.biz/questions/21354992/an-error-occurred-in-the-secure-channel-support-classic-asp-http-request#39448696

    I recomend check all keys and subkeys’ registry related to this update before any change to learn what change and offer a clear and consistent solution to yours followers.

    Microsoft has a MicrosoftEasyFix51044.msi that create some keys but not all
    Update: KB3140245 (Doesn’t create all the keys and subkeys)

    I got a raw HTTP after whr.ResponseText. After that one have to adjust/modify the Regex function, task that i’m going to be waiting from you and, if is comented, it would be highly appreciated.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s