[AHK] Switch to active DOpus list path in Save As/Open Dialogue with MiddleClick

I am sharing my latest script with Autohotkey, that does the trick of "Bringing your Save As/Open dialogue directly to the path of your active DOpus list".
This is the feature inspired by Commercial software Listary, and another Autohotkey project Quick Access Popup by [Jean Lalonde].
And the code are based on other github project, mentioned in the code below.

; a fork from above script, which works for Windows Explorer, author: Leeroy
; further, above script was inspired by author: Savage
; the script works with Directory Opus, but with below prerequisites:
;  1. Your DOpus setting has set the title bar starts with "DOpus"
;  2. Your DOpus seeting has set the title bar "Display full path"
; in my case, I set the title bar "DOpus | C:\xxxxxx", hence my script will cut off 8 chacters from the title string
; please adapt the script on your own to fit your settings
#SingleInstance, Force
#KeyHistory, 0
SetBatchLines, -1
ListLines, Off
SendMode Input ; Forces Send and SendRaw to use SendInput buffering for speed.
SetTitleMatchMode, 2 ; 
#MaxThreadsPerHotkey, 1 ; no re-entrant hotkey handling

;   two sets of keys, both active
; Middle-MouseButton, CTRL+G, like Listary
f_Hotkey = ~MButton
f_HotkeyCombo = ~^g

; Auto-execute section.
Hotkey, %f_Hotkey%, f_Jump2ActivePath
Hotkey, %f_HotkeyCombo%, f_Jump2ActivePath

;validate the correct dialogue type
WinGet, f_window_id, ID, a
WinGetClass, f_class, a
; Don't display menu unless it's a dialog or console window
if f_class not in #32770,ConsoleWindowClass

; get the path from Dopus
WinGet, id, list, ahk_exe dopus.exe			;get IDs for all DOpus windows
    Loop, %id% 							;Loop through IDs of all DOpus windows
        this_ID := id%A_Index%
        WinGetTitle, Title, ahk_id %this_ID%			;get the title of the current window
        StringLeft, Left6, Title, 6
        ; MsgBox, %Left6%
        ; if Left6=="DOpus "
        ; {
            StringLen, TitleLen, Title 
            StringRight, DopusPath, Title, TitleLen-8
            ; MsgBox, %DopusPath%
        ; }
    ; return

if f_class = #32770 ; It's a dialog.
    ; Activate the window so that if the user is middle-clicking
    ; outside the dialog, subsequent clicks will also work:
    WinActivate ahk_id %f_window_id%
    ; Alt+D to convert Address bar from breadcrumbs to editbox
    Send !{d}
    ; Wait for focus
    Sleep 50
    ; The control that's focused after Alt+D is thus the address bar
    ControlGetFocus, addressbar, a
    ; Put in the chosen path
    ControlSetText %addressbar%, % DopusPath, a
    Sleep 50
    ; Go there
    ControlSend %addressbar%, {Enter}, a
    ; Return focus to filename field
    ControlFocus Edit1, a
; In a console window, pushd to that directory
else if f_class = ConsoleWindowClass
    ; Because sometimes the mclick deactivates it.
    WinActivate, ahk_id %f_window_id%
    ; This will be in effect only for the duration of this thread.
    SetKeyDelay, 0
    ; Clear existing text from prompt and send pushd command
    Send, {Esc}pushd %DopusPath%{Enter}

Currently it's not perfect -- sometimes you need to click more times :wink:
Any feedback and improve suggestion are welcome!

I always have only one instance of Directory Opus open.
The DOpus window title is set to display full path and nothing more
I unchecked the option to display localized folder names

#SingleInstance ignore
setTitleMatchMode, 2
^G::		;Ctrl + G to use in Open/Save dialogs to go to path active in  DOpus									
WinGetTitle, vOpus, ahk_class dopus.lister	
send, %vOpus%								
send, {ENTER}								

To be able to use the middle mouse button I added:

#ifWinActive, Open					
WinGetTitle, vOpus, ahk_class dopus.lister
send, %vOpus%							
send, {ENTER}							
#ifWinActive, Save					
WinGetTitle, vOpus, ahk_class dopus.lister
send, %vOpus%							
send, {ENTER}							

My knowledge of AHK is "average", but this is working fine for me.

Hi, Ennovy,
that looks very Lean!
But your code will apply to all the scenarios of input and you have to firstly select the address bar and the CTRL+G kicks in, correct?

My solution is intended to implement Listary that you can click MButton anywhere as soon as you are at the Save As/Open dialogue.

Also the looping through of Dopus process are to exclude you have setting windows open, to be error-proof.
BTW I think your solution of Mbutton will mislead with only filtering by window title, e.g. I've one document title with "Open", and "Stadardized Open dialogue" are using different title for the dialogue actually, "Open"/"Open File" --> error proofing could be a concern.

But, yes, yours would work just fine in majority ocasions and with much less effort.

Thanks for sharing.

I don't have a need for the script to be error proof, I know where and when to use it

you have to firstly select the address bar and the CTRL+G kicks in, correct?

No, I Don't have to

Hi, Ennovy,
I'm sharing a script to the community, so that I have to be more thoughtful on error-proofing.
And I am clarifying your script's specification so that other users may consider valuable, too.

Everybody believes his own tool is good if he keep it for his own use.

So I'd skip more discussion here.
Thank you.

Please tell me how to install this script in my PC & How to Use it?

The first result in Google for "how do I install AHK scripts" looks good: Using the Program | AutoHotkey