Jump to a specified file immediately after start

English support forum

Moderators: white, Hacker, petermad, Stefan2

Post Reply
azazell0
Junior Member
Junior Member
Posts: 8
Joined: 2006-03-15, 23:16 UTC

Jump to a specified file immediately after start

Post by *azazell0 »

Currently, one can only specify the folder in which TC must start in. I think it would be useful if TC could be started with focus on a file specified in the command line, like

totalcmd.exe c:\autoexec.bat

What do you think?
User avatar
van Dusen
Power Member
Power Member
Posts: 684
Joined: 2004-09-16, 19:30 UTC
Location: Sinzig (Rhein), Germany

Post by *van Dusen »

Hello azazell0,

yes, would be wonderful! It needs a "start at file" command line parameter for TC and a new internal command ("cm_GotoNamedFile" for instance... yes, I know: "cm_" commands doesn't accept parameters, so it should be implemented like "ftpopen" or "opentabs"?) too. AFAIR, this requirement has been already discussed several times in this forum.

As a workaround, you can call TC by this AutoIT-script, which originally was written to jump to a specific file in TC from within "Locate32":

Code: Select all

;====================================================================================================
;LocateAndJump, van Dusen. 2006-01-31
;Script for AutoIT3 (http://www.autoitscript.com/autoit3/)
;Settings for Locate32:
;Menu Settings, Dialog "Settings:", Tab "Keyboard Shortcuts":
;   Shortcut: Key:                     STRG + F
;   Advanced: Advanced Settings: Type: Local
;   Where pressed:                     Result list
;   Action: Action:                    Advanced
;   Action: SubAction:                 Execute Command
;   Action: Command:                   C:\Programme\AutoIt3\AutoIt3.exe C:\Programme\TotalCmd\Tools\LocateAndJump.au3 "%d"
;                                      (Locate32 seems not to decode environment variables like "%ProgramFiles%")
;Usage:
;Find a file wth Locate32, press STRG+F to open the containing dir in TC and to jump to the located file
;====================================================================================================

$fullname = $CmdLine[1]
$fullname_tok = StringSplit($fullname, "\")
$filename = $fullname_tok[$fullname_tok[0]]
$pathname = StringLeft($fullname, StringLen($fullname) - StringLen($filename) - 1)

Run(@ProgramFilesDir & "\TotalCmd\TotalCmd.exe /O /T /S /L=" & Chr(34) & $pathname & Chr(34), "")

;*** cm_ShowQuickSearch=2915;Show name search window
Sleep(250)
DllCall("user32.dll", "int", "SendMessage", "hwnd", WinGetHandle("Total Commander"), "int", 1075, "int", 2915)

Send($filename, 1)
Send("{ESC}")
;Send("{SPACE}")
Usage (if not started ba hotkey from Locate32):
LocateAndJump[.exe] "Z:\Path\To\File.ext"
Or
[X:\Path\To\]AutoIT.exe [Y:\Path\To\]LocateAndJump.au3 "Z:\Path\To\File.ext"

To pass through other command line parameters to TC, the script should be slightly modified. If you like to try a compiled standalone-version of this script, just ask for it here.
azazell0
Junior Member
Junior Member
Posts: 8
Joined: 2006-03-15, 23:16 UTC

Post by *azazell0 »

Thanks, now I know what AutoIt is. I finally got your script working (had to set the sleep to 1500ms), but there is still a problem: despite the /L switch, the folder is always opened on the last side active. Any idea?
User avatar
van Dusen
Power Member
Power Member
Posts: 684
Joined: 2004-09-16, 19:30 UTC
Location: Sinzig (Rhein), Germany

Post by *van Dusen »

Sorry for answering late...

The command line switch /S in TotalCmd.exe /O /T /S /L="{path}" alters the meaning of the /L and /R switches: If /S is present, then /L references the "active panel" instead of the "left panel" and /R means "inactive panel" instead of "right panel".

BTW: The /T switch seems not to work... it should open the given path in a new tab, but it doesn't do so.

Here is a modified script. It waits for the TC window (timeout after 5s) and the quick search edit box (timeout after 2s), thus the Sleep statement should be unnecessary. In case of a timeout the script tries to play a sound; this is just a gimmick - you can delete both Else and SoundPlay code lines, if you like:

Code: Select all

AutoItSetOption("WinTitleMatchMode", 4)
;AutoItSetOption("SendKeyDelay", 10)

$fullname = $CmdLine[1]
$fullname_tok = StringSplit($fullname, "\")
$filename = $fullname_tok[$fullname_tok[0]]
$pathname = StringLeft($fullname, StringLen($fullname) - StringLen($filename) - 1)

;Run(@ProgramFilesDir & "\TotalCmd\TotalCmd.exe /O /T /S /L=" & Chr(34) & $pathname & Chr(34), "")
Run(@ProgramFilesDir & "\TotalCmd\TotalCmd.exe /O /T /L=" & Chr(34) & $pathname & Chr(34), "")
If WinWait("classname=TTOTAL_CMD", "", 5) Then
	;*** cm_ShowQuickSearch=2915;Show name search window
	DllCall("user32.dll", "int", "SendMessage", "hwnd", WinGetHandle("classname=TTOTAL_CMD"), "int", 1075, "int", 2915)
	If WinWaitActive("classname=TQUICKSEARCH", "", 2) Then
		Send($filename, 1)
		Send("{ESC}")
		;Send("{SPACE}")
	Else
		SoundPlay(StringReplace(RegRead("HKCU\AppEvents\Schemes\Apps\.Default\SystemAsterisk\.Current", ""), "%SystemRoot%", @WindowsDir), 1)
	EndIf
Else
	SoundPlay(StringReplace(RegRead("HKCU\AppEvents\Schemes\Apps\.Default\SystemAsterisk\.Current", ""), "%SystemRoot%", @WindowsDir), 1)
EndIf
User avatar
Lefteous
Power Member
Power Member
Posts: 9535
Joined: 2003-02-09, 01:18 UTC
Location: Germany
Contact:

Post by *Lefteous »

2van Dusen
The /T switch seems not to work... it should open the given path in a new tab, but it doesn't do so.
maybe this is related to:
http://www.ghisler.ch/board/viewtopic.php?t=9434
User avatar
van Dusen
Power Member
Power Member
Posts: 684
Joined: 2004-09-16, 19:30 UTC
Location: Sinzig (Rhein), Germany

Post by *van Dusen »

2Lefteous

Ah, you are right, now I remember this thread... in deed, it's a similar problem, probably it originates from the same bug.
azazell0
Junior Member
Junior Member
Posts: 8
Joined: 2006-03-15, 23:16 UTC

Post by *azazell0 »

van Dusen:

Thanks, works great. :wink:
azazell0
Junior Member
Junior Member
Posts: 8
Joined: 2006-03-15, 23:16 UTC

Post by *azazell0 »

Well... there seems to be yet another problem with this script, because now it works only when Total Commander isn't already open. Any idea?

By the way, isn't there a possibility to utilize the Go to file command in Find? It does exactly what we need.
azazell0
Junior Member
Junior Member
Posts: 8
Joined: 2006-03-15, 23:16 UTC

Post by *azazell0 »

Well, I know it's been a lot of time, but I finally found a solution (after learning some autoit): replace th line

If WinWait("classname=TTOTAL_CMD", "", 5) Then

with

If WinWaitActive("classname=TTOTAL_CMD", "", 5) Then
Post Reply