Skip to content

Instantly share code, notes, and snippets.

Last active February 9, 2024 15:58
  • Star 27 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save akaleeroy/f23bd4dd2ddae63ece2582ede842b028 to your computer and use it in GitHub Desktop.
Easy Access to Currently Opened Folders

Easy Access to Currently Opened Folders

Windows Enhancement Productivity

Enhance Open... or Save As... dialogs with a quick way to navigate to currently opened folders.

Easy Access to Currently Opened Folders - Demo

This is an AutoHotkey script that gives common file selection dialogs an extra feature: middle-clicking invokes a menu of currently opened folders. Say you want to save or upload something to/from a folder you've got open in Windows Explorer. The dialog box pops up with the last folder (from another project) or My Documents, and now you have to manually navigate to the folder you want, or copy-paste its path from the open Explorer window. I wanted to get to the active locations quicker. Recent Items wasn't exactly helping, so I made this by forking FavoriteFolders.ahk by Savage. Tested on Windows 7, 8, 10.

How it works

You run the script in the background the whole time Windows is on. I included it into another script with more helper functions and compiled it to an executable which is set to start with Windows.

  1. When one of these file selection dialogs pops up, Middle Click inside it. Or hit Ctrl + G. These are configurable at the top of the script.

  2. A menu appears with your current working directories.

  3. Select one and the script will quickly insert it in the dialog's address bar and take you there.

  4. Save or select your file.


Special places like Computer, Libraries, Search results etc. won't show up in the menu.


Fix Brittleness Support old-style dialogs. Regedit Export dialog is one of them and it doesn't work there. But not with Edit1, try to work around Send !d for targetting address bar to navigate. See SelectFolderEx()

; Easy Access to Currently Opened Folders
; Original author: Savage
; Fork by Leeroy
; Invoke a menu of currently opened folders when you click
; the middle mouse button inside Open / Save as dialogs or
; Console (command prompt) windows. Select one of these
; locations and the script will navigate there.
; You could also use a modified mouse button (such as ^MButton) or
; a keyboard hotkey. In the case of MButton, the tilde (~) prefix
; is used so that MButton's normal functionality is not lost when
; you click in other window types, such as a browser.
; Middle-click like original script by Savage
f_Hotkey = ~MButton
; Ctrl+G like in Listary
f_HotkeyCombo = ~^g
; Do not make changes below this point unless you want to change
; the basic functionality of the script.
#SingleInstance, force ; Needed since the hotkey is dynamically created.
; Auto-execute section.
Hotkey, %f_Hotkey%, f_DisplayMenu
Hotkey, %f_HotkeyCombo%, f_DisplayMenu
; Navigate to the chosen path
; Set destination path to be the selected menu item
f_path = %A_ThisMenuItem%
if f_path =
if f_class = #32770 ; It's a dialog.
; Activate the window so that if the user is middle-clicking
; outside the dialog, subsequent clicks will also work:
WinActivate ahk_id %f_window_id%
; Alt+D to convert Address bar from breadcrumbs to editbox
Send !{d}
; Wait for focus
Sleep 50
; The control that's focused after Alt+D is thus the address bar
ControlGetFocus, addressbar, a
; Put in the chosen path
ControlSetText %addressbar%, % f_path, a
; Go there
ControlSend %addressbar%, {Enter}, a
; Return focus to filename field
ControlFocus Edit1, a
; In a console window, pushd to that directory
else if f_class = ConsoleWindowClass
; Because sometimes the mclick deactivates it.
WinActivate, ahk_id %f_window_id%
; This will be in effect only for the duration of this thread.
SetKeyDelay, 0
; Clear existing text from prompt and send pushd command
Send, {Esc}pushd %f_path%{Enter}
SetTimer, RemoveToolTip, Off
; Display the menu
; Get active window identifiers for use in f_Navigate
WinGet, f_window_id, ID, a
WinGetClass, f_class, a
; Don't display menu unless it's a dialog or console window
if f_class not in #32770,ConsoleWindowClass
; Otherwise, put together the menu
GetCurrentPaths() {
For pwb in ComObjCreate("Shell.Application").Windows
; Exclude special locations like Computer, Recycle Bin, Search Results
If InStr(pwb.FullName, "explorer.exe") && InStr(pwb.LocationURL, "file:///")
; Get paths of currently opened Explorer windows
Menu, CurrentLocations, Add, % pwb.document.folder.self.path, f_Navigate
; Same default folder icon for all
Menu, CurrentLocations, Icon, % pwb.document.folder.self.path, %A_WinDir%\system32\imageres.dll, 4
; Get current paths and build menu with them
; Don't halt the show if there are no paths and the menu is empty
Menu, CurrentLocations, UseErrorLevel
; Present the menu
Menu, CurrentLocations, Show
; If it doesn't exist show reassuring tooltip
If ErrorLevel
; Oh! Look at that taskbar. It's empty.
ToolTip, No folders open
SetTimer, RemoveToolTip, 1000
; Destroy the menu so it doesn't remember previously opened windows
Menu, CurrentLocations, Delete
Copy link

Acecool commented Dec 26, 2016

If you only have one folder open and you middle click > release middle click > left-click only folder > release left-click - it will save to the currently opened folder instead of switching to the selected folder... I just saved the web-page and wanted to save to downloads and thought it worked when it automatically closed the SaveAs window after selecting the downloads folder... But, then I opened folder location and it was the previous folder in SaveAs... When 2 folders are open, clicking on 1 actually switches the folder.

Copy link

@Acecool I'm unable to reproduce this. It isn't supposed to automatically save anyway, just to take you to the folder. I've just tested a Windows 8 machine and it didn't navigate on the first try though. So maybe there is a problem with the address bar control targeting.

Copy link

akaleeroy commented Jan 8, 2017

Just found out this feature is available in Listary:

Quick Switch

Are you tired of digging through a slew of open windows to work with files in a program? With Listary’s Quick Switch feature, just click Ctrl+G to instantly jump to the open folder of the file you’re working with.


Also done in Quick Access Popup by Jean Lalonde
This software is actually an AutoHotkey project, loaded with features!

▷ Folders Popup - Switch between current folders demo

Copy link

Wow! This is a really sweet code.
It works with Visual Studio Code, but doesn't seem to work with Word, Excel, or any other Program I've used it with though :(

Copy link

akaleeroy commented Oct 14, 2019


doesn't seem to work with Word, Excel, or any other Program I've used it with though :(

The code is simple enough for the standard Common Item Dialog. Unfortunately there are many exceptions: the old kind of dialog used by RegEdit for example, and of course custom dialogs used by various software suites (LibreOffice, Blender). These edge cases are difficult to address, especially while keeping the code simple. I haven't felt the burning need to do so, and it would take me a long time because I'm not a professional programmer.

I do use this script daily. Where it is supported it really helps. If you want to make heavy use of this functionality in a program where this doesn't work you could try the pro alternatives mentioned above, or just make do with "abusing" a clipboard manager to copy-paste paths (as long as there is an address bar).

Copy link

Is there something we can do this same as Listary does

Copy link

Is there a mac version of this function? Please, I need this function on Mac OS.

Copy link

Brilliant script! One of my biggest annoyances with Windows over the years. Oh how many copy/pastes I've had to alt-tab + alt-D + alt-N between. Thanks for sharing!

Copy link

ghost commented May 5, 2022

Is there something we can do this same as Listary does

by ahk v2 you can check here

global LastActiveFolder := "下載"
#HotIf WinExist("ahk_class #32770") & WinActive("ahk_exe explorer.exe")
MouseGetPos , , &id, &control

for window in ComObject("Shell.Application").Windows
    If (window.LocationName == WinGetTitle(id)) {
		pwd := SubStr(window.LocationURL, 9)
		pwd := 	StrReplace(pwd, "/", "\",, &Count)
		pwd := 	StrReplace(pwd, "%20", " ",, &Count)	
		if (Count = 0)
		global LastActiveFolder := pwd
	Send "{Click}"

#HotIf WinActive("ahk_class #32770")
	If (LastActiveFolder == "下載") {
	global LastActiveFolder := "C:\Users\" A_Username "\Downloads"
	} else {
	ControlFocus "Edit1"
	ControlSetText(LastActiveFolder, "Edit1")
	ControlSend "{Enter}", "Button2"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment