As per https://autohotkey.com/board/topic/102127-navigating-explorer-directories/#entry634365 and https://docs.microsoft.com/en-us/windows/win32/shell/shell, I've experimented with using the COM object Shell.Application but I've found that it only lists the existing File Explorer CabinetWClass (normal) windows, not the existing #32770 ("Open", "Save As", etc) windows open in other applications. You can see this for yourself by running the following PowerShell commands:
Code: Select all
$Shell = New-Object -ComObject Shell.Application
ForEach ($Item in $Shell.windows()) {
Write-Host $Item.LocationName
}
Code: Select all
If ((WinActive("ahk_class #32770")) And (WinActive("Save As") Or WinActive("Save Print Output As") Or WinActive("Open"))){
If (NewFolderPath != ""){
ControlGetText, CurrentFolderPath, ToolbarWindow324, A
CurrentFolderPath := StrReplace(CurrentFolderPath, "Address: ")
If (CurrentFolderPath != NewFolderPath){
; Alt and D is a native Windows hotkey for selecting the address bar
SendInput, !d %NewFolderPath% {Enter}
; The above command doesn't seem to be synchronous so triggering ControlFocus too early won't work
Sleep 400
; Selecting the address bar changes focus from the file name box so this sets it back
ControlFocus, Edit1, A
}
}
}
Thanks.
Edit 2020/10/26 12:20: I've managed to fine-tune the code to the following which speeds up the operation and makes it a bit more precise but I'd still prefer a more elegant solution if possible:
Code: Select all
If (WinActive("ahk_class #32770") And (WinActive("Save As") Or WinActive("Save Print Output As") Or WinActive("Open"))){
If (NewFolderPath != ""){
ControlGetText, CurrentFolderPath, ToolbarWindow324, A
CurrentFolderPath := StrReplace(CurrentFolderPath, "Address: ")
If (CurrentFolderPath != NewFolderPath){
; Alt and D is a native Windows hotkey for selecting the address bar
SendInput, !d
Sleep, 50
ControlSetText, Edit2, %NewFolderPath%
ControlSend, Edit2, {Enter}
; Selecting the address bar changes focus from the file name box so this sets it back
ControlFocus, Edit1, A
}
}
}