First of all my code:
#t::
IfWinActive, ahk_class CabinetWClass ; If explorer is active
{
path := GetActiveExplorerPath()
Run wt.exe -d "%path%"
}
else
{
Run wt.exe
}
Return
; https://stackoverflow.com/questions/39253268/autohotkey-and-windows-10-how-to-get-current-explorer-path
GetActiveExplorerPath() {
explorerHwnd := WinActive("ahk_class CabinetWClass")
if (explorerHwnd)
{
for window in ComObjCreate("Shell.Application").Windows
{
if (window.hwnd==explorerHwnd)
return window.Document.Folder.Self.Path
}
}
}
Now if I press [Superkey] + [t]
then the terminal opens as intended. However, a bug occurs if there is a space in the path variable, i.e. C:\Users\user\AHK Macros
.
Fixing this should be easy (wrapping it in double quotes) and it works. The problem now is that opening the terminal at the C:\
directory results in an error. I think it has something to do with C:\
ending in a "\", thus escaping the quotation mark. Not sure though. I have tried wrapping it in 3/4 quotes. Printing it with MsgBox
does give the desired "C:/"
result and I am able to open C:/
if I leave out the quotation marks. What am I overlooking?