AutoHotkey: Automatic directory-specific configuration / actions
This script periodically "looks" into Total Commander to see what the current directory is and based on that information it sends user-defined commands to TC. These commands can be whatever you desire them to be, starting from sorting by date, invoking a custom columns view, to starting your media player.
The first part of the script defines the interval at which AutoHotkey checks the path in the active panel of Total Commander. The default is 1000 milliseconds (1 second). Smaller values increase reaction speed, however, they might slow things down if you are just passing through the directory. Larger values will make the action trigger later.
Place this at the beginning of the script:
#Persistent SetTimer, TCDirSpecificActions, 1000 return
The second part of the script defines what actions belong to what directories, and at the end you define the "default" action, that is what to do when you are in neither of the "special" directories.
Place this anywhere in the script:
TCDirSpecificActions: IfWinActive, ahk_class TTOTAL_CMD { WinGetText, Text, A Loop, Parse, Text, `n { If A_Index = 3 { StringTrimRight, Dir, A_LoopField, 2 Break } } If Dir <> %PreviousDir% { ; This is the first section ; On the line below you define what directory this section is triggered by ; (directory names with spaces must be typed without quotes) If Dir = c:\Music { ; Value "271" means activate custom columns view #1 ; (these values correspond to the values in your totalcmd.inc) PostMessage, 1075, 271 PreviousDir = %Dir% return } ; This is the second section ; If you want actions to be done recursively, ; for instance for "c:\Images and Photos" and all its subdirs ; use the IfInString format IfInString, Dir, c:\Images and Photos { ; Value "272" means activate custom columns view #2 PostMessage, 1075, 272 PreviousDir = %Dir% return } ; This is the third section If Dir = c:\Downloads { ; Value "272" means sort by date PostMessage, 1075, 324 PreviousDir = %Dir% return } ; This is the DEFAULT section ; Here you must place all the actions to get back your "normal" view If PreviousDir <> DEFAULT { ; Activate Brief view PostMessage, 1075, 301 PreviousDir = DEFAULT } } } return
Back to AutoHotkey