MsgBox with info (app, directory, etc) for active window

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
WeThotUWasAToad
Posts: 312
Joined: 19 Nov 2013, 08:44

MsgBox with info (app, directory, etc) for active window

12 Mar 2017, 20:31

Hello,

I'm trying to create a MsgBox which returns information for the active window including:

• active window title
• directory/pathway for the active file
• window screen position
• name of the application executable file
• directory/pathway for the executable file

Here is the script I've got so far but it's missing some things. (Note: The underscores are present to show indents and will be replaced by spaces — unless someone can tell me how to include actual indents in a MsgBox.)

Code: Select all

^F7::
	WinGetActiveStats, `Title, Width, Height, X, Y
	WinGet, appName, ProcessName
	WinGet, filePath, ProcessPath
		MsgBox, The active title is: 
			(Join
				`n________"%Title%"
				`n
				`nThe active file directory/pathway is:
				`n________
				`n
				`nThe window position is:
				`n________%X%, %Y%, %Width%, %Height%
				`n
				`nThe application executable file is:
				`n________%appName%
				`n
				`nThe executable file is located here:
				`n________%filePath%
			)
	Return
I don't know what command captures the active window's pathway/directory. Also, I'm obviously doing something wrong with the lines containing ProcessName and ProcessPath. I thought they would give me the name of the executable file and its location based on the following from the WinGet page in the docs:

Syntax:
WinGet, OutputVar [, Cmd, WinTitle, WinText, ExcludeTitle, ExcludeText]

Comments:
Cmd is the operation to perform, which if blank defaults to ID. It can be one of the following words:
...
ProcessName: Retrieves the name of the process (e.g. notepad.exe) that owns a window. If there are no matching windows, OutputVar is made blank.

ProcessPath [v1.1.01+]: Similar to ProcessName, but retrieves the full path and name of the process instead of just the name.
...
Thanks

PS Also, which term (pathway or directory) is most appropriate where I have included both of them above?
A ------------------------------ [A LOT OF SPACE] ------------------------------ LOT

"ALOT" is not a word. It never has been a word and it never will be a word.
"A LOT" is 2 words. Remember it as though there's [A LOT OF SPACE] between them.
imustbeamoron
Posts: 44
Joined: 18 Aug 2016, 22:56

Re: MsgBox with info (app, directory, etc) for active window

12 Mar 2017, 21:39

not sure what your looking for in the active file directory.. its the same as the path. anyways.. hope this is of some help

Code: Select all

^F7::
	winHwnd := WinExist("A")								;get handle of active window
	WinGetActiveStats, `Title, Width, Height, X, Y
	WinGet, appName, ProcessName, ahk_id %winHwnd%
	WinGet, filePath, ProcessPath, ahk_id %winHwnd%
		MsgBox, The active title is: 
			(Join
				`n %A_Tab% "%Title%"
				`n
				`nThe active file directory/pathway is:
				`n %A_Tab%
				`n
				`nThe window position is:
				`n %A_Tab% %X%, %Y%, %Width%, %Height%
				`n
				`nThe application executable file is:
				`n %A_Tab% %appName%
				`n
				`nThe executable file is located here:
				`n %A_Tab% %filePath%
			)
	Return
User avatar
JnLlnd
Posts: 487
Joined: 29 Sep 2013, 21:29
Location: Montreal, Quebec, Canada
Contact:

Re: MsgBox with info (app, directory, etc) for active window

13 Mar 2017, 08:13

I'm trying to create a MsgBox which returns information for the active window including:
• directory/pathway for the active file
You probably mean the current location inside the Explorer window? The code added to your script will make sure this is an Explorer window and, if yes, retrieve the current location by grabbing the location text box. The sleep command is used foir safety, based on experience.

Code: Select all

^F7::
	winHwnd := WinExist("A")								;get handle of active window
	WinGetActiveStats, `Title, Width, Height, X, Y
	WinGet, appName, ProcessName, ahk_id %winHwnd%
	WinGet, filePath, ProcessPath, ahk_id %winHwnd%
	WinGetClass, WindowClass, ahk_id %winHwnd%

	if (WindowClass = "CabinetWClass") or (WindowClass = "ExploreWClass")
	{
		PrevClipboard := ClipboardAll ; Save the entire clipboard
		ClipBoard := ""
		intWaitTimeIncrement := 150 ; time allowed for Explorer
		intTries := 3
		Loop, %intTries%
		{
			Sleep, intWaitTimeIncrement * A_Index
			SendInput, {F4}{Esc} ; F4 move the caret the "Go To A Different Folder box" and {Esc} select it content ({Esc} could be replaced by ^a to Select All)
			Sleep, intWaitTimeIncrement * A_Index
			SendInput, ^c ; Copy
			Sleep, intWaitTimeIncrement * A_Index
			intTriesIndex := A_Index
		} Until StrLen(ClipBoard)
		CurrentLocation := ClipBoard
		Clipboard := PrevClipboard ; Restore the original clipboard
	}
	else
		CurrentLocation := "Not an Explorer window"
	
		MsgBox, The active title is: 
			(Join
				`n %A_Tab% "%Title%"
				`n
				`nThe active file directory/pathway is:
				`n %A_Tab%%CurrentLocation%
				`n
				`nThe active window class is:
				`n %A_Tab%%WindowClass%
				`n
				`nThe window position is:
				`n %A_Tab% %X%, %Y%, %Width%, %Height%
				`n
				`nThe application executable file is:
				`n %A_Tab% %appName%
				`n
				`nThe executable file is located here:
				`n %A_Tab% %filePath%
			)
	Return
:thumbup: Author of freeware Quick Access Popup, the powerful Windows folders, apps and documents launcher!
:P Now working on Quick Clipboard Editor
:ugeek: The Automator's Courses on AutoHotkey
WeThotUWasAToad
Posts: 312
Joined: 19 Nov 2013, 08:44

Re: MsgBox with info (app, directory, etc) for active window

28 Mar 2017, 00:19

JnLlnd, thanks a bunch for this script. It's almost exactly what I was after and I see you also included a new line to display the Class. That's much appreciated.
JnLlnd wrote:
I'm trying to create a MsgBox which returns information for the active window including:
• directory/pathway for the active file
You probably mean the current location inside the Explorer window? The code added to your script will make sure this is an Explorer window and, if yes, retrieve the current location by grabbing the location text box.
I'm not sure I understand the above statement from your post. What I mean by the "directory/pathway" (if one of those is the correct term) is where the active window/file is located on the hard drive.

Obviously that does not apply all the time (eg I'm in Google Chrome right now and there's no related file location that I'm interested in knowing) but in other windows (eg MS Office files, Notepad++ files, PDF files, etc), it would be helpful to have a quick way to know exactly where the file displayed in the active window is located (eg C:\Users\Steve\Documents\AHK\Test01.ahk or D:\From SATA 1TB HD\Main\0_Dailies\Past files\PhoneDirectory.xlsm, etc).

By the way, I rarely use Windows Explorer in case that is relevant. My default File Manager is Directory Opus. Might that explain the 2nd line in the MsgBox saying: "The active file directory/pathway is: Not an Explorer window" even though the active window is an Excel spreadsheet?

Thanks again
A ------------------------------ [A LOT OF SPACE] ------------------------------ LOT

"ALOT" is not a word. It never has been a word and it never will be a word.
"A LOT" is 2 words. Remember it as though there's [A LOT OF SPACE] between them.
User avatar
JnLlnd
Posts: 487
Joined: 29 Sep 2013, 21:29
Location: Montreal, Quebec, Canada
Contact:

Re: MsgBox with info (app, directory, etc) for active window

28 Mar 2017, 12:05

WeThotUWasAToad wrote:What I mean by the "directory/pathway" (if one of those is the correct term) is where the active window/file is located on the hard drive.
Same thing for me.
WeThotUWasAToad wrote:in other windows (eg MS Office files, Notepad++ files, PDF files, etc), it would be helpful to have a quick way to know exactly where the file displayed in the active window is located (eg C:\Users\Steve\Documents\AHK\Test01.ahk or D:\From SATA 1TB HD\Main\0_Dailies\Past files\PhoneDirectory.xlsm, etc).
I do not know how to retrieve this information. This would require to dig inside the MS app object model. Not sure if this can be done using AHK.

On the other hand, when an MS Office app file dialog box (File Open, File, Save As) is active, the current folder in a can be retrieved with the following changes to the code.

Code: Select all

^F7::
	winHwnd := WinExist("A")								;get handle of active window
	WinGetActiveStats, `Title, Width, Height, X, Y
	WinGet, appName, ProcessName, ahk_id %winHwnd%
	WinGet, filePath, ProcessPath, ahk_id %winHwnd%
	WinGetClass, WindowClass, ahk_id %winHwnd%

	if (WindowClass = "CabinetWClass") or (WindowClass = "ExploreWClass") or (WindowClass = "#32770")
	{
		PrevClipboard := ClipboardAll ; Save the entire clipboard
		ClipBoard := ""
		intWaitTimeIncrement := 150 ; time allowed for Explorer
		intTries := 3
		Loop, %intTries%
		{
			Sleep, intWaitTimeIncrement * A_Index
			SendInput, {F4}{Esc} ; F4 move the caret the "Go To A Different Folder box" and {Esc} select it content ({Esc} could be replaced by ^a to Select All)
			Sleep, intWaitTimeIncrement * A_Index
			SendInput, ^c ; Copy
			Sleep, intWaitTimeIncrement * A_Index
			intTriesIndex := A_Index
		} Until StrLen(ClipBoard)
		CurrentLocation := ClipBoard
		Clipboard := PrevClipboard ; Restore the original clipboard
	}
	else
		CurrentLocation := "Not an Explorer or dialog box window"
	
		MsgBox, The active title is: 
			(Join
				`n %A_Tab% "%Title%"
				`n
				`nThe active file directory/pathway is:
				`n %A_Tab%%CurrentLocation%
				`n
				`nThe active window class is:
				`n %A_Tab%%WindowClass%
				`n
				`nThe window position is:
				`n %A_Tab% %X%, %Y%, %Width%, %Height%
				`n
				`nThe application executable file is:
				`n %A_Tab% %appName%
				`n
				`nThe executable file is located here:
				`n %A_Tab% %filePath%
			)
	Return
WeThotUWasAToad wrote:By the way, I rarely use Windows Explorer in case that is relevant. My default File Manager is Directory Opus. Might that explain the 2nd line in the MsgBox saying: "The active file directory/pathway is: Not an Explorer window" even though the active window is an Excel spreadsheet?
This is not related to DOpus being your file manager. This is because XL is the active window.

Jean
:thumbup: Author of freeware Quick Access Popup, the powerful Windows folders, apps and documents launcher!
:P Now working on Quick Clipboard Editor
:ugeek: The Automator's Courses on AutoHotkey
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: MsgBox with info (app, directory, etc) for active window

28 Mar 2017, 14:38

Regarding your layout issue, a `t (AKA a tab) should work out fine (eg instead of that %A_Tab%) :thumbup: > [more ..]

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 136 guests