AutoHotkey: Show the active path in the title bar extended

From TotalcmdWiki
Jump to navigation Jump to search

Based on AutoHotkey: Show the active path in the title bar (by SanskritFritz).

This version keeps important information from the original window title (TC instance number, RunAs-user, TC version).
To get more space it can shorten the program name from "Total Commander" to "TC" (optionally).

#SingleInstance, Force
#Persistent
	; ////////////////////////////////////////////////////////////////////////////
	; // TC_ActivePathInWinTitle.ahk V1.03 - (W) StatusQuo 2009-2020
	; // 
	; // show TC's current path in WinTitle
	; ////////////////////////////////////////////////////////////////////////////

if FileExist("TC_ActivePathInWinTitle.ico")
	Menu, Tray, Icon, TC_ActivePathInWinTitle.ico
Menu, Tray, Tip , TC - Path In WinTitle V1.03 - (W) STQ 2009-2019

boAppendToOrgTitle := 1	; *** 1 = keep RunAs-user and TC version in title
boShortenTcName    := 1	; *** 1 = replace "Total Commander" with "TC"

sTcTitleName1 := "Total Commander"
sTcTitleName2 := "TC"
sTcTitleName  := sTcTitleName1

SetTimer TaskSched_PathInTitle, 100
Return


TaskSched_PathInTitle:
if WinActive( "ahk_class TTOTAL_CMD" )
{
	ControlGetText,    sPath, Window5	; *** TC9.22a 64bit w/o FTP-connection
	If (not (InStr(sPath, "\"))) and (not (InStr(sPath, "/")))	; If (sPath = "")
		ControlGetText, sPath, Window6	; *** TC9.50 64bit w/o FTP-connection / TC9.22a w/  FTP-Connection
	If (not (InStr(sPath, "\"))) and (not (InStr(sPath, "/")))
		ControlGetText, sPath, Window7	; *** TC9.50 64bit w/  FTP-connection
	If (not (InStr(sPath, "\"))) and (not (InStr(sPath, "/")))
		ControlGetText, sPath, TMyPanel3	; *** TC9.50 32bit w/o FTP-connection / TC9.22a regardless of FTP-connection
	If (not (InStr(sPath, "\"))) and (not (InStr(sPath, "/")))
		ControlGetText, sPath, TMyPanel4	; *** TC9.50 32bit w/  FTP-connection
	If (not (InStr(sPath, "\"))) and (not (InStr(sPath, "/")))
		ControlGetText, sPath, TMyPanel2
	sPath := SubStr(sPath, 1, StrLen(sPath) - 1)
	WinGetTitle, sWinTitle1
	if (sWinTitle1 = "")
		Return	; *** could not get current title - wait for next run
	sWinTitle := sWinTitle1
	
		; *** title is reset after minimizing - find out current state
	if (iTitlePos      := InStr(sWinTitle, sTcTitleName1 . " "))
		sTcTitleName    := sTcTitleName1
	else
		if (iTitlePos   := InStr(sWinTitle, sTcTitleName2 . " "))
			sTcTitleName := sTcTitleName2

		; *** shorten original program name
		;     "user - Total Commander... - regname or path"
	if (boShortenTcName)
	{
		if (iTitlePos := InStr(sWinTitle, sTcTitleName . " "))	; "Total Commander " / "TC "
		{
			sWinTitle := SubStr(sWinTitle, 1, iTitlePos - 1) . sTcTitleName2 . SubStr(sWinTitle, iTitlePos + StrLen(sTcTitleName))
			sTcTitleName := sTcTitleName2
		}
	}
	
	if (boAppendToOrgTitle)
	{	; *** keep original title part
		if (iWinTitleEnd := InStr(sWinTitle, sTcTitleName . " ", true))	; *** "Total Commander " / "TC "
			iWinTitleEnd  := InStr(sWinTitle, " - ", false, iWinTitleEnd) + 2	; *** end of program  name
		sNewTitle := SubStr(sWinTitle, 1, iWinTitleEnd) . sPath
	} else {	; *** set title to path only
		sNewTitle := sPath
	}
	if (sWinTitle1 != sNewTitle)
		if WinActive( "ahk_class TTOTAL_CMD" )	; *** prevent affecting other windows
			WinSetTitle, ahk_class TTOTAL_CMD,, %sNewTitle%
}
Return 


Back to AutoHotkey