Open current File Explorer window in DOpus?

NEWTAB=findexisting is not valid for the file path

AutoHotkey script

; Ctrl+E Redirect Explorer Window to DOpus

#Requires AutoHotkey v2
#SingleInstance
try TraySetIcon("shell32", 265)      ; Set the tray icon


DOpusPath := "C:\Program Files\GPSoftware\Directory Opus\dopusrt.exe"

HotIfWinActive "ahk_class CabinetWClass"
Hotkey "Ctrl & E", RedirectToDOpus
HotIf



; Redirect Explorer window to DOpus --------------------------------------------------------------------------------------------------

RedirectToDOpus(*) {
    if !explorerItems := explorerGetSelection()
		return
	explorerItemsArray := strSplit(explorerItems, "`n")
	item := explorerItemsArray[1]
	if (item = "::{F874310E-B6B7-47DC-BC84-B9E6B38F5903}")
		item := "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}"   ; This PC
	commandLine := '"' DOpusPath '" /acmd=Go "' item '" NEWTAB=deflister,findexisting,tofront'
	winHwnd := winActive("A")
	try {
		run commandLine
		winClose winHwnd
	} catch
		trayTip("The program path does not exist, please modify it in the script!", "RedirectExplorerWindow", 2)
}



; Explorer get selection --- Modified from ntepa's code ------------------------------------------------------------------------------

explorerGetSelection(hwnd := WinExist("A")) {   ; by ntepa -- https://www.autohotkey.com/boards/viewtopic.php?p=529074#p529074
    if !winExist(hwnd) || !RegExMatch(WinGetClass(hwnd), "^((?<Desktop>Progman|WorkerW)|CabinetWClass)$", &Match)
        return
    shellWindows := ComObject("Shell.Application").Windows
    ; get desktop or explorer window.
    if Match.Desktop ; 0x13 = VT_UI4, 0x8 = SWC_DESKTOP
        window := shellWindows.Item(ComValue(0x13, 0x8)).Document
    else {
        try activeTab := ControlGetHwnd("ShellTabWindowClass1", hwnd)
        for w in shellWindows {
		    try {
                if w.hwnd != hwnd
                    continue
                if IsSet(activeTab) {
                    IID_IShellBrowser := "{000214E2-0000-0000-C000-000000000046}"
                    shellBrowser := ComObjQuery(w, IID_IShellBrowser, IID_IShellBrowser)
                    ComCall(3, shellBrowser, "uint*", &thisTab:=0)
                    if thisTab != activeTab
                        continue
                }
                window := w.Document
                break
			}
        }
    }

    Items := ""
    try for i, in window.SelectedItems {
        Items .= (A_Index > 1 ? "`n" : "") i.Path ; append each selected item and add a new line.
    }
	else
        return window.Folder.Self.Path
	catch
	    for window in shellWindows
		    try if (window.hwnd==hwnd)
				for i, in window.SelectedItems
                    Items .= (A_Index > 1 ? "`n" : "") i.Path ; append each selected item and add a new line.

    return Items
}
1 Like