Command Line: switch to existing tab if path matches
Moderators: Hacker, petermad, Stefan2, white
Command Line: switch to existing tab if path matches
I often open favorite folders with Autohotkey shortcuts (e.g. Win+1 to open Documents, Win+2 to open Downloads etc), and I also use them to switch to my file explorer (instead of alt-tabbing or using bottom bar, because then I'd still need to open the proper tab there, which is less convenient).
Now, I've set up TC as default in Windows 10, so whenever I try to open a folder, it intercepts and opens a new tab with this folder (I have `/T` switch on).
Here is the deal — my previous explorer substitution (QTTab) was able to understand that the passed folder path is already open and would just open the existing tab instead of opening an identical tab.
However, TC doesn't do that — it always opens a new tab even when I already have several of the same folders open. Is it possible to change this behavior and check whether passed path is already open and don't multiply same tabs?
Also, would it be possible to have an option to force new tabs to be opened in currently ACTIVE pane? (I know there are options to specify left or right regardless of what pane you're currently working in)
Thank you!
Now, I've set up TC as default in Windows 10, so whenever I try to open a folder, it intercepts and opens a new tab with this folder (I have `/T` switch on).
Here is the deal — my previous explorer substitution (QTTab) was able to understand that the passed folder path is already open and would just open the existing tab instead of opening an identical tab.
However, TC doesn't do that — it always opens a new tab even when I already have several of the same folders open. Is it possible to change this behavior and check whether passed path is already open and don't multiply same tabs?
Also, would it be possible to have an option to force new tabs to be opened in currently ACTIVE pane? (I know there are options to specify left or right regardless of what pane you're currently working in)
Thank you!
Hi eugenesv,
HTH
Roman
Nope, at least not that I know of.Is it possible to change this behavior and check whether passed path is already open and don't multiply same tabs?
/SAlso, would it be possible to have an option to force new tabs to be opened in currently ACTIVE pane?
HTH
Roman
Mal angenommen, du drückst Strg+F, wählst die FTP-Verbindung (mit gespeichertem Passwort), klickst aber nicht auf Verbinden, sondern fällst tot um.
eugenesv,
I think this topic may be interesting for you. There is no way to jump to existing tab but it is easy to close duplicate tabs when you change directory.
With TCFS2 it is easy to send em_CdUnique command (mentioned here) to existing TC instance so your AHK shortcuts may also be easilly adapted to such scheme:
I think this topic may be interesting for you. There is no way to jump to existing tab but it is easy to close duplicate tabs when you change directory.
With TCFS2 it is easy to send em_CdUnique command (mentioned here) to existing TC instance so your AHK shortcuts may also be easilly adapted to such scheme:
Code: Select all
TCFS2.exe /ef "tem(`em_CdUnique x:\path\to\be\opened`)"
Thanks for the suggestion! But it's a 32bit addon and I'm using the 64bit versionMVV wrote:eugenesv,
I think this topic may be interesting for you. There is no way to jump to existing tab but it is easy to close duplicate tabs when you change directory.
With TCFS2 it is easy to send em_CdUnique command (mentioned here) to existing TC instance so your AHK shortcuts may also be easilly adapted to such scheme:Code: Select all
TCFS2.exe /ef "tem(`em_CdUnique x:\path\to\be\opened`)"


It's a bit strange, though, that this specific command isn't bindable by default in the list of TC commands.
By the way, given that your addon deals with UI elements, maybe you know theanswer to another issue I have with TC (I originally raised this at http://ghisler.ch/board/viewtopic.php?t=43677&highlight=).
I was investigating whether I can use my favorite terminal ConEmu inside TC just like I can do it inside Windows Explorer and realized that it's possible only partially — I wasn't able to find the proper 0xHWND ID of the insides of a given panel. I've found the top/bottom parts where I can inject ConEmu, but the middle part with actual list of folder/files is inaccessible.
You can see more details with screenshots from discussion with the author of ConEmu
https://github.com/Maximus5/ConEmu/issues/122
So, I have two questions you might know the answer to:
1) Is there an HWND (this is a hex window code of a window object, which can be a panel, status bar, command line etc.) of the middle of the panel that shows folder/files (I couldn't find any in Spy++)?
2) Is there an addon (maybe yours

Thank you!
TCFS2 is usable regardless of the TC version.eugenesv wrote:Thanks for the suggestion! But it's a 32bit addon and I'm using the 64bit versionMVV wrote:eugenesv,
I think this topic may be interesting for you. There is no way to jump to existing tab but it is easy to close duplicate tabs when you change directory.
With TCFS2 it is easy to send em_CdUnique command (mentioned here) to existing TC instance so your AHK shortcuts may also be easilly adapted to such scheme:Code: Select all
TCFS2.exe /ef "tem(`em_CdUnique x:\path\to\be\opened`)"
( Are you planning to update this to 64bit
It's a bit strange, though, that this specific command isn't bindable by default in the list of TC commands.
...
Its not a plugin and so is no need for a x64 version.
@Horst.Epp, thanks for clarification, got it all set up now.
@MVV this is an awesome hack, exactly what I need — no tabs spreading like viruses!
However, I couldn't get AutoHotkey to launch it properly, maybe it has something to do with the escape quotes
The original command gives out a straight error "Function not implemented! em_CdUniqueE:\"
A slightly modified version (with double backticks) does switch the current tab to target path, but then instead of closing the duplicates it just opens a tab right-mouse-button context menu and stops there.
Any hints on the proper syntax when launching it from an external process via AutoHotkey? Or command line for that matter — I get the same result running it from Win+R
Much appreciated
@MVV this is an awesome hack, exactly what I need — no tabs spreading like viruses!
However, I couldn't get AutoHotkey to launch it properly, maybe it has something to do with the escape quotes
The original command
Code: Select all
#2:: Run C:\Dev\totalcmd\plugins\TCFS2\TCFS2.exe /ef "tem(`em_CdUnique E:\1`)"
A slightly modified version (with double backticks)
Code: Select all
#2:: Run C:\Dev\totalcmd\plugins\TCFS2\TCFS2.exe /ef "tem(``em_CdUnique E:\1``)"
Any hints on the proper syntax when launching it from an external process via AutoHotkey? Or command line for that matter — I get the same result running it from Win+R
Much appreciated
eugenesv,
You've forgot to define em_CdUnique command in TC (mentioned here as it was noted above).
BTW TCFS2 description on totalcmd.net explicitly tells that the tool works with 64-bit TC:
You've forgot to define em_CdUnique command in TC (mentioned here as it was noted above).

BTW TCFS2 description on totalcmd.net explicitly tells that the tool works with 64-bit TC:
There is no 64-bit version just because there is no need in it.Program works with both 32-bit and 64-bit TC versions.

No I haven't forgotten anything. As I mentioned above, it works just fine when I invoke that command inside TC (after I add backquotes). It's when I'm trying to invoke this command outside (e.g. from Win-R or Autohotkey) something breaks down.
There is something happening that prevents the em_CdUnique command complete the operation and do the final Up-Enter sequence.
Btw, I've noticed that sometimes Narrator spawns when I run this command (I renamed the file, so there are just strayed processes in Process Explorer), so that's maybe it. Can this em_CdUnique command somehow invoke Windows Narrator? Or maybe it's still just a syntax issue — something should be escaped or something to properly pass all the arguments intact.
There is something happening that prevents the em_CdUnique command complete the operation and do the final Up-Enter sequence.
Btw, I've noticed that sometimes Narrator spawns when I run this command (I renamed the file, so there are just strayed processes in Process Explorer), so that's maybe it. Can this em_CdUnique command somehow invoke Windows Narrator? Or maybe it's still just a syntax issue — something should be escaped or something to properly pass all the arguments intact.
Something I've noticed: spaces were cut down so command name have merged with path.
It seems that AHK somehow modifies command line and loses some characters like quotes or accents (TCFS2 removes spaces from expressions before inner processing except strings in grave accents)...
You can try to invoke e.g. notepad.exe instead of TCFS2.exe and get resulting process command line using process manager like Process Hacker in order to check if command line is correct.
It seems that AHK somehow modifies command line and loses some characters like quotes or accents (TCFS2 removes spaces from expressions before inner processing except strings in grave accents)...
You can try to invoke e.g. notepad.exe instead of TCFS2.exe and get resulting process command line using process manager like Process Hacker in order to check if command line is correct.
Ignoring AHK for a moment as it just adds an unnecessary layer of complexity, are you able to run this command from the default Run window on your computer?
When I try the original command
with single backquotes and single quotes, it seems to open the context menu (I see it flash for a split second, I don't see the text in it, it's too brief, but from the size and position of it it's the tab context menu), but then closes without selecting the "Close duplicate tabs" command, so the "Up, Enter" sequence key isn't registered or something
P.S.
By the way, is there a simpler way to reach custom commands from within TC?
Currently I have to do Configuration->Options->Misc->Select Hotkey->Search->Select usercmd.ini->Select command em_CdUnique->Edit?
Or is it only directly editing usercmd.ini?
When I try the original command
Code: Select all
TCFS2.exe /ef "tem(`em_CdUnique E:\1`)"
P.S.
By the way, is there a simpler way to reach custom commands from within TC?
Currently I have to do Configuration->Options->Misc->Select Hotkey->Search->Select usercmd.ini->Select command em_CdUnique->Edit?
Or is it only directly editing usercmd.ini?
Hm, it may not work fine when TC has no focus (in that topic it had it), so em_CdUnique may require adding some waiting for context menu window, it needs some experiments (we need context menu window for executing 'close duplicate tabs' action from it, and this menu should have focus when TCFS2 sends keypresses - perhaps you can send keypresses from your AHK).
But if you only need to manage custom commands, you can start cm_CommandBrowser directly. Editing usercmd.ini directly is also possible but it is not a preferred way (e.g. because of quoting rules in INI files).
If you need to create a command and set a hotkey for it at once, this is a shortest way.By the way, is there a simpler way to reach custom commands from within TC?
But if you only need to manage custom commands, you can start cm_CommandBrowser directly. Editing usercmd.ini directly is also possible but it is not a preferred way (e.g. because of quoting rules in INI files).
Thank you! I've bound this to a custom icon on my toolbar and now it's one-click instead of twenty steps.you can start cm_CommandBrowser directly
Re. focus I think you're spot on, but delays don't help

I'm now running a slightly modified command that sets the path directly (just for testing) and I notice when I run it externally (from Win+R) TC only regains focus AFTER it's executed (its title bar is greyed out aka in the background for the whole command duration, including changing directory and opening context menu
Code: Select all
C:\Dev\totalcmd\Addons\TCFS2\TCFS2.exe /ef "eval(tcd(`C:\`,,S)+delay(500)+msg($433,3009,,1)+delay(500)+send(`{UP}{ENTER}`))"
Or maybe there is a direct way to focus TC (think there should be one in AHK, but then I'd have to adjust the syntax first, which I wanted to avoid to fix this issue)?
Or anything else?
Got it!!!
I now do everything in AHK without invoking the internal em_CdUnique command (I think it was also a problem with passing command line parameters where escaping caused an issue and command failed because it was interpeted differently from what it would've been if passed internally)
Here is my AHK command (just as an example Win+2 Opens "C:\" and closes all duplicate tabs):
1. Every comma has to be escaped with a backtick for AHK to process it properly.
2. Keys sent directly via AHK — this way you can avoid the issue of command failing if you hold another key (Up-Enter gets mixed with that key). There is a special send mode in AHK that allows to ignore keyboard presses during command execution.
3. Slight delay is necessary for it to work as sometimes AHK sends input too fast — before context menu has spawned (play with exact delay (in milliseconds) to make it work for you). Is something else is happening too fast, just instert another delay before that process.
4. It opens a new tab at the start so that you don't get your active tab overwritten with the CD command
Declare main function TotalCMD_CD to CD to a passed path and close duplicate tabs.
And use the function to CD to your heart's desire
P.S.
The issue resolution below might not be relevant anymore with the adjusted AHK script that ignores user keypresses during command execution, but leaving it anyway as it's a helpful tip on how to kill Narrator:
Now the only issue remaining is those stupid Narrator processes (rather AtBroker.exe processes trying to spawn Narrator since I renamed the Narrator executable) that spawn if I hold Win key for half a second too long. I'll need to check out which shortcuts spawn it and how to disable them (though it's too deeply embedded to be honest)
UPDATE: and to get rid of that stupid Narrator spawning on Win+Enter (which is exactly what's being passed if I held Winkey a bit too long, though maybe could change something in AHK to ignore it) check out the second solution @https://superuser.com/questions/473410/disable-narrator-shortcut-key-in-windows-8 (this will also prevent those rogue AtBroker.exe processes from spawning as well!
P.P.S.
Supporting function isn't needed anymore as I remembered I could open a new tab by passing a few command line parameters to TC directly, but again leaving just in case
Declare supporting function RunActivate that either opens TC if it's not open or activates it if it's not active
I now do everything in AHK without invoking the internal em_CdUnique command (I think it was also a problem with passing command line parameters where escaping caused an issue and command failed because it was interpeted differently from what it would've been if passed internally)
Here is my AHK command (just as an example Win+2 Opens "C:\" and closes all duplicate tabs):
1. Every comma has to be escaped with a backtick for AHK to process it properly.
2. Keys sent directly via AHK — this way you can avoid the issue of command failing if you hold another key (Up-Enter gets mixed with that key). There is a special send mode in AHK that allows to ignore keyboard presses during command execution.
3. Slight delay is necessary for it to work as sometimes AHK sends input too fast — before context menu has spawned (play with exact delay (in milliseconds) to make it work for you). Is something else is happening too fast, just instert another delay before that process.
4. It opens a new tab at the start so that you don't get your active tab overwritten with the CD command
Declare main function TotalCMD_CD to CD to a passed path and close duplicate tabs.
Code: Select all
TotalCMD_CD(CDTo) {
; RunActivate("c:\Dev\totalcmd\TOTALCMD64.EXE") ; not needed anymore as avoding dupliate TC instance is checked by TC itself via/O
; SendInput ^{VK54} ;t VK54 SC014 ; not needed anymore as opening a new tab by TC itself
Run, C:\Dev\totalcmd\TOTALCMD64.EXE /O /S /T %CDTo%
Sleep 100 ; a simple wait until TC is launched (too short to bother with a conditional check)
Run, C:\Dev\totalcmd\Addons\TCFS2\TCFS2.exe /ef "eval(tcd(``%CDTo%```,`,S)+msg($433`,3009`,`,1))"
Sleep 100
SendInput {UP}{ENTER} ; Ingores user's keypresses
Return
}

Code: Select all
#2::TotalCMD_CD("C:\")
P.S.
The issue resolution below might not be relevant anymore with the adjusted AHK script that ignores user keypresses during command execution, but leaving it anyway as it's a helpful tip on how to kill Narrator:
Now the only issue remaining is those stupid Narrator processes (rather AtBroker.exe processes trying to spawn Narrator since I renamed the Narrator executable) that spawn if I hold Win key for half a second too long. I'll need to check out which shortcuts spawn it and how to disable them (though it's too deeply embedded to be honest)
UPDATE: and to get rid of that stupid Narrator spawning on Win+Enter (which is exactly what's being passed if I held Winkey a bit too long, though maybe could change something in AHK to ignore it) check out the second solution @https://superuser.com/questions/473410/disable-narrator-shortcut-key-in-windows-8 (this will also prevent those rogue AtBroker.exe processes from spawning as well!
P.P.S.
Supporting function isn't needed anymore as I remembered I could open a new tab by passing a few command line parameters to TC directly, but again leaving just in case
Declare supporting function RunActivate that either opens TC if it's not open or activates it if it's not active
Code: Select all
RunActivate(Program, WorkingDir="", WindowSize="") {
SplitPath Program, ExeFile
Process, Exist, %ExeFile%
PID = %ErrorLevel%
If (PID = 0) {
Run, %Program%, %WorkingDir%, %WindowSize%
} Else {
SetTitleMatchMode,2
DetectHiddenWindows, Off
IfWinActive, ahk_pid %PID%
Return
Else
IfWinExist, ahk_pid %PID%
WinActivate, ahk_pid %PID%
Return
}
}
I have no Narrator problems with old good Windows 7. 
Well, you don't need to start TOTALCMD.exe if you pass cd command via TCFS2. BTW, you can pass it from AHK too (search forum for WM_COPYDATA examples). Passing command from TCFS2 or AHK is faster than starting new TOTALCMD.exe.
There may be focus problems when active window doesn't allow losing focus (e.g. when I start TCFS2 from console window, it always gets focus back so I can't send keypresses to TC window but I can perfectly start TCFS2 from TC buttonbar or via a hotkey).
Anyway, it is great that you've finally got it working.

Well, you don't need to start TOTALCMD.exe if you pass cd command via TCFS2. BTW, you can pass it from AHK too (search forum for WM_COPYDATA examples). Passing command from TCFS2 or AHK is faster than starting new TOTALCMD.exe.
There may be focus problems when active window doesn't allow losing focus (e.g. when I start TCFS2 from console window, it always gets focus back so I can't send keypresses to TC window but I can perfectly start TCFS2 from TC buttonbar or via a hotkey).
Anyway, it is great that you've finally got it working.
