Detect current folder in Windows "Select Folder"-Dialog Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
Spitzi
Posts: 313
Joined: 24 Feb 2022, 03:45

Detect current folder in Windows "Select Folder"-Dialog

Post by Spitzi » 15 Oct 2023, 14:57

Hi there.

The app I am trying to automate, has a settings window, where the path to a cache-folder can be set. I would like to find out the path to that folder using ahk.
So far, with ahk and the UIA-Interface (by @Descolada ), I can click on the "select folder" icon to open a dialog, and the currently set cache-folder is displayed in a typical "select folder"-dialog.

How can I find out the currentliy open folder in this dialog? I tried to rightclick the adressbar using UIA, which works, and a context menu is displayed. But I can't figure out how to click the "copy address as text" menu entry.

Code: Select all

		
		toolbarEl := UIA.ElementFromHandle(automatedAppWinName).FindElement({Type:"SplitButton", Name:"all locations"})			; address toolbar 
		toolbarEl.ControlClick("right")																				; rightclick on that toolbar
		Sleep(200)
		menuEl := UIA.ElementFromHandle(automatedAppWinName).FindElement({Type:"MenuItem", Name:"copy address as text""})		; UIA access to the context menu - this line fails (element not found)
		menuEl.Click("left")
Is the context menu part of a different window? Thanks for any help.

WKen
Posts: 184
Joined: 21 Feb 2023, 00:01

Re: Detect current folder in Windows "Select Folder"-Dialog

Post by WKen » 15 Oct 2023, 16:01

Get the text of a control? Usually 324, may be 323.

Code: Select all

F3::ToolTip strSplit(ControlGetText("ToolbarWindow324", "ahk_class #32770"), ": ")[2]

Spitzi
Posts: 313
Joined: 24 Feb 2022, 03:45

Re: Detect current folder in Windows "Select Folder"-Dialog  Topic is solved

Post by Spitzi » 03 Nov 2023, 08:43

Thanks WKen

your code did not work for me. Instead, I figured it out using UIA (windows localisation in german)

Code: Select all

			; 2) in folder dialog, rightclick on adress bar and copy adress path
			toolbarEl := UIA.ElementFromHandle(WinTitle).FindElement({Type:"SplitButton", Name:"Alle Speicherorte"})
			toolbarEl.ControlClick("right")
			Sleep(200)
			; menuEl := UIA.ElementFromHandle(merlinWinTitle).FindElement({Type:"MenuItem", Name:"Adresse als Text kopieren"})					; not working - menu element is not found
			menuEl := UIA.GetRootElement().FindElement({Type:"MenuItem", Name:"Adresse als Text kopieren"})										; need to search from desktop root element to find menu element
			menuEl.Click("left")																												; click the menu item
			if !ClipWait(1)																														; wait for clipboard to contain text
				Throw Error("Clipboard remainded empty")
			cachePath := SubStr(A_Clipboard, -5) == "cache" ?  A_Clipboard : A_Clipboard "\cache"
			; ToolTip(cachePath)

Post Reply

Return to “Ask for Help (v2)”