[AHK] Permanent Synchronous directory changing

Discuss and announce Total Commander plugins, addons and other useful tools here, both their usage and their development.

Moderators: white, Hacker, petermad, Stefan2

Post Reply
User avatar
LonerD
Senior Member
Senior Member
Posts: 381
Joined: 2010-06-19, 20:18 UTC
Location: Makeyevka, Russia
Contact:

[AHK] Permanent Synchronous directory changing

Post by *LonerD »

Permanent Synchronous directory changing
-- Inspired from this thread.

I never use the cm_SyncChangeDir command, it's useless in its current state.
Sometimes you want to enter into a directory knowing that there is no equivalent on the other side and you don't want the SyncChangeDir flag to be reset.

This script performs one simple action:
First call. Script runs and works in the background. Script remembers current directories (paths) on the left and right panels. When you return to this directories - synchronization is turned on, when you left directories - synchronization is turned off.
Second call. Disable synchronization and exit script.

Default TC behaviour - GIF1
AHK Script behaviour - GIF2

Code: Select all

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;
; Total Commander DreamLair                        ;
; Script: Sinchronize dirs changes                 ;
; Скрипт: Синхронна зміна каталогів                ;
; Скрипт: Синхронное изменение каталогов           ;
; Script name: SyncChangeDir.ahk                   ;
; Script author: LonerD                            ;
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;

#NoEnv
#NoTrayIcon
#Persistent
#SingleInstance Off
SetBatchLines, -1
DetectHiddenWindows, On

if CloseCopy() || RegExMatch(StrGet(DllCall("GetCommandLine", Ptr)), "i)\s/(restart|r|force|f)\s")
{
  SendMessage, 1075, 2600, -1,, ahk_class TTOTAL_CMD
  ExitApp
}

CloseCopy()
{ 
  WinGet, List, List, % A_ScriptFullPath " ahk_class AutoHotkey"
  Loop % List
    if WinExist("ahk_id" List%A_Index%) != A_ScriptHwnd && res := true
      WinClose
  Return res
}

WinGet, hw_TTOTAL_CMD, ID, A
SendMessage, 1075, 2600, 1,, % "ahk_id " hw_TTOTAL_CMD

SendMessage, 1074, 9, 0,, % "ahk_id " hw_TTOTAL_CMD
ControlGetText, PathL,, % "ahk_id " ErrorLevel
SendMessage, 1074, 10, 0,, % "ahk_id " hw_TTOTAL_CMD
ControlGetText, PathR,, % "ahk_id " ErrorLevel

SetTimer SyncChange, 50

SyncChange:
  if not ( WinExist("ahk_class TTOTAL_CMD") || WinActive("ahk_class TTOTAL_CMD") )
    ExitApp
  SendMessage, 1074, 9, 0,, % "ahk_id " hw_TTOTAL_CMD
  ControlGetText, PathLnew,, % "ahk_id " ErrorLevel
  SendMessage, 1074, 10, 0,, % "ahk_id " hw_TTOTAL_CMD
  ControlGetText, PathRnew,, % "ahk_id " ErrorLevel
  if ( ( PathLnew = PathL ) & ( PathRnew = PathR ) )
    ; cm_SyncChangeDir , 1 (включение функции)
    SendMessage, 1075, 2600, 1,, % "ahk_id " hw_TTOTAL_CMD
Return
Thanks Fla$her for idea with second call and unload script.
"I used to feel guilty in Cambridge that I spent all day playing games, while I was supposed to be doing mathematics. Then, when I discovered surreal numbers, I realized that playing games IS math." John Horton Conway
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48075
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: [AHK] Permanent Synchronous directory changing

Post by *ghisler(Author) »

Sometimes you want to enter into a directory knowing that there is no equivalent on the other side and you don't want the SyncChangeDir flag to be reset.
I I didn't reset the flag in this case, then going up from that directory would also go up on the other side, and the two would become desynchronized. Example:
c:\base
d:\base
Go into
c:\base\subdir
but remain at
d:\base
Then when the user goes back up to
c:\base
the right side would go to
d:\
Author of Total Commander
https://www.ghisler.com
Post Reply