1

I'm using autohotkey and try to do this:

  • Open download folder (Q:\Down in my case) or activate it if already opened (subfolders don't count, for example still open Q:\Down if I opened Q:\Down\phvideos already)

Script I'm using

Run "Q:\Down"

or

Run % "explorer /expand, Q:\Down\"

Both of them can open such a folder, but activate it again will open a duplicate window in explorer.

Is there any command that opens unique folder, or detects if given folder path exists in an opened explorer window?

2
  • The first example is exactly what I use to do this for a local folder. I don't use quotes on either end but I wouldn't expect that to matter. It may be different for folders that are on the same drive where Windows is installed but that would also be surprising. Run should work the same way the shell's Run command works. May 7, 2022 at 13:34
  • It works, wtf I was doing by searching the Internet for 3 hours, I already got the solution already lol....dunno why it didn't work when I test it the first time, thanks dude
    – Byzod
    May 7, 2022 at 13:39

2 Answers 2

0

If you have the option

"Display the full path in the title bar" enabled,

you can use

SetTitleMatchMode, 3
If WinExist("Q:\Down ahk_class CabinetWClass")
    WinActivate
else
    Run % "explorer /expand, Q:\Down\"

Otherwise you can try this:

Run_explorer("Q:\Down")

Run_explorer(path) {
    If InStr(explorer_list(), path)
    {
        Loop, Parse, % explorer_list(), `n
        {
            If InStr(A_LoopField, path)
            {
                ID := StrSplit(A_LoopField,"_").1
                WinActivate, ahk_id %ID%
                    break
            }
        }
    }
    else
        Run % path
}

explorer_list() {
    ; Get ID + fullpath of all opened explorer windows:
    If WinExist("ahk_class CabinetWClass") ; explorer
    {
        list := ""
        ; https://autohotkey.com/boards/viewtopic.php?p=28751#p28751
        for window in ComObjCreate("Shell.Application").Windows
        {
            try explorer_path := window.Document.Folder.Self.Path
            If (explorer_path = "")
                continue
            WinGet, ID, ID, % explorer_path
            list .= ID "_" explorer_path ? ID "_" explorer_path "`n" : "" 
        }
        list := trim(list, "`n")
        return list
    }
}
0

I already forgot this question lol, this is my script rn, to help future users

global DOWNLOAD_FOLDER := "K:\Down"
; win + q   Open Down
#q::
{
    downWinTitle := "Down ahk_class CabinetWClass"
    WinGet explorerHwnd, ID, % downWinTitle
    path := GetExplorerPath(explorerHwnd)
    if(!explorerHwnd || path != DOWNLOAD_FOLDER){
        Run % "explorer /expand, " . DOWNLOAD_FOLDER
        WinWait % downWinTitle
        WinGet explorerHwnd, ID, % downWinTitle
    }
    WinActivate % "ahk_id " . explorerHwnd
    Return
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .