Search code examples
windowsautohotkeywindows-explorer

Open-save dialog automatically opens the folder which is currently opened in Windows Explorer


I want to realize a program which works in this way: I have a folder opened in Windows Explorer. I'm working in a program and I want to save my work. I open the Open/save dialog and I'd like to have a shortcut to automatically jump to the folder which is currently opened in Windows Explorer.

I think AutoHotKey should do the trick but I don't know how to go on. Perhaps the best solution is:

  • set a shortcut to save the currently active folder in Windows Explorer
  • set another shortcut which make the currently opened open-save dialog jump to the saved directory.

Is it possible to realize that in AHK? How to do it?


Solution

  • Example (using a new notepad document):

    #IfWinActive ahk_class Notepad
    
        F1::
            explorer_path := "" ; empty variable
            IfWinNotExist ahk_class CabinetWClass ; explorer
                return  ; do nothing
            ; otherwise:
            ; https://autohotkey.com/boards/viewtopic.php?p=28751#p28751
            ; get the path of the first explorer window:
            for window in ComObjCreate("Shell.Application").Windows
            {
                try explorer_path := window.Document.Folder.Self.Path
                        break
            }
            ; MsgBox, %explorer_path%
            Send, ^s ; save the new document
            ; wait for the Save As window and activate it
            WinWait, Save As ahk_class #32770
            WinActivate, Save As ahk_class #32770
            WinWaitActive, Save As ahk_class #32770
            ; open the folder "explorer_path" in Save As
            SendInput, %explorer_path%
            Sleep, 300
            Send, {Enter}
        return
    
    #IfWinActive