AutoHotkey: Paste TC's active path anywhere: Difference between revisions

From TotalcmdWiki
Jump to navigation Jump to search
m (SendRaw instead of just Send is more error proof)
(Added a new method to retrieve the path (working since TC 9.0))
 
(3 intermediate revisions by 2 users not shown)
Line 2: Line 2:
<br />
<br />
<br />
<br />
''Short version:''
  #IfWinExist, ahk_class TTOTAL_CMD
  #IfWinExist, ahk_class TTOTAL_CMD
   
   
  ; Default shortcut is Win-A
  ''; Default shortcut is Win-A''
$#a::
''; Read the text that is currently shown in TC's window''
DetectHiddenText, On
WinGetText, TCWindowText
''; Find the string that ends in '>' - that should be the current path''
RegExMatch(TCWindowText, "\n(.*)>", TCPath)
SendRaw, %TCPath1%\
Return
 
 
''Short version (working in TC 9.0 and later):''
#IfWinExist, ahk_class TTOTAL_CMD
''; Default shortcut is Win-A''
  $#a::
  $#a::
''; Get the handle of the control that contains the current path''
SendMessage, 1074, 17
   
   
  ; Read current TC dir from the panel left of the command line
  ''; Get the current path''
  ControlGetText, Path, TMyPanel2
WinGetText, PathInTC, ahk_id %ErrorLevel%
''; Cut off the trailing > and newline signs''
StringTrimRight, PathInTC, PathInTC, 3
  Send, {Raw}%PathInTC%\
Return
 
 
''Long version:''
#IfWinExist, ahk_class TTOTAL_CMD
''; Default shortcut is Win-A''
$#a::
HiddenTextDetectionSetting = %A_DetectHiddenText%
DetectHiddenText, On
   
   
  ; Replace the trailing > with a \
  ''; Read the text that is currently shown in TC's window''
  StringReplace, Path, Path, >, \
  WinGetText, TCWindowText
DetectHiddenText, %HiddenTextDetectionSetting%
HiddenTextDetectionSetting =
   
   
  ; Type it
  ''; Find the string that ends in '>' - that should be the current path''
SendRaw, %Path%
Loop, Parse, TCWindowText, `n, `r
{
StringRight, LastChar, A_LoopField, 1
IfEqual, LastChar, >
{
StringTrimRight, TCPath, A_LoopField, 1
''; Type it into the currently active window / control''
SendRaw, %TCPath%\
Return
}
}
  Return
  Return


Line 49: Line 93:
<br />
<br />
Back to [[AutoHotkey]]
Back to [[AutoHotkey]]
[[Category:AutoHotkey scripts|Paste TC's active path anywhere]]

Latest revision as of 20:28, 9 July 2017

This script pastes the path from TC's active panel to any window that is currently active. Should be especially useful for Save or Open dialog boxes. It was inspired by majkinetor's TC Fav Menu.

Short version:

#IfWinExist, ahk_class TTOTAL_CMD

; Default shortcut is Win-A
$#a::
	; Read the text that is currently shown in TC's window
	DetectHiddenText, On
	WinGetText, TCWindowText

	; Find the string that ends in '>' - that should be the current path
	RegExMatch(TCWindowText, "\n(.*)>", TCPath)
	SendRaw, %TCPath1%\
Return


Short version (working in TC 9.0 and later):

#IfWinExist, ahk_class TTOTAL_CMD

; Default shortcut is Win-A
$#a::
	; Get the handle of the control that contains the current path
	SendMessage, 1074, 17

	; Get the current path
	WinGetText, PathInTC, ahk_id %ErrorLevel%

	; Cut off the trailing > and newline signs
	StringTrimRight, PathInTC, PathInTC, 3
	Send, {Raw}%PathInTC%\
Return


Long version:

#IfWinExist, ahk_class TTOTAL_CMD

; Default shortcut is Win-A
$#a::
	HiddenTextDetectionSetting = %A_DetectHiddenText%
	DetectHiddenText, On

	; Read the text that is currently shown in TC's window
	WinGetText, TCWindowText
	DetectHiddenText, %HiddenTextDetectionSetting%
	HiddenTextDetectionSetting =

	; Find the string that ends in '>' - that should be the current path
	Loop, Parse, TCWindowText, `n, `r
	{
		StringRight, LastChar, A_LoopField, 1
		IfEqual, LastChar, >
		{
			StringTrimRight, TCPath, A_LoopField, 1
			; Type it into the currently active window / control
			SendRaw, %TCPath%\
			Return
		}
	}
Return


Alternative version, using the clipboard:

#IfWinExist, ahk_class TTOTAL_CMD

; Default shortcut is Win-A
$#a::

	; Backup the clipboard
	ClipboardBackup = %ClipboardAll%

	; Empty the clipboard
	Clipboard =

	; Ask TC for the path
	PostMessage, 1075, 2029, , , ahk_class TTOTAL_CMD

	; Wait at most 2 seconds for the path
	; You can change the value below
	ClipWait, 2

	; Paste and append a backslash
	; You can remove the backslash from the following line if you prefer
	Send, ^v\

	; Restore clipboard from backup
	Clipboard = %ClipboardBackup%

	; Release memory
	ClipboardBackup =
Return


Back to AutoHotkey