Scripts/macro’s/menu’s with more than one command?

English support forum

Moderators: white, Hacker, petermad, Stefan2

Post Reply
Ernest de Vroome
Junior Member
Junior Member
Posts: 3
Joined: 2007-10-01, 22:24 UTC
Location: Utrecht, Holland

Scripts/macro’s/menu’s with more than one command?

Post by *Ernest de Vroome »

Is it possible in TC to create a script/macro/menu to do several "things" one after the other, all just by pressing the same user-defined button only once?

For instance if I want TC to do the following one after the other…

Set the left pane on: “g:\school-projects” [e.g. my USB stick]
Set the right pane on: “s:\school-projects” [e.g. the office network]
Now issue the command: “synchronize directories”
Then when this synchronizing is done [by “manually” pressing the desired buttons etc.], the “macro” should automatically go to the next “line”, and continue:
...now set the left pane on: “g:\work-products”, and the right pane on: “s:\work-products”, then synchronize these directories, and when done, go to the third specific comparison and so on and so on. It should also be easy to add one or two new directories to the “macro”, and drop old ones as time goes by.

Synchronizing “g” and “s” in total would be to time consuming, as there are more than 2.000 directories on “s” and I only want to synchronize “my own” 20 directories at most.

I already know how to store previous synchronizations and use them again, and even know how to put a single synchronization under a button with the command “SYNCOPEN”. But I would really want the entire synchronization-process in one large “macro” (a bit like in visual basic for applications)?!

So, is this possible in TC and how is it done (or where can I read how it is done)?

Thanks a lot if someone could help me out with this, Ernest
icfu
Power Member
Power Member
Posts: 6052
Joined: 2003-09-10, 18:33 UTC

Post by *icfu »

http://www.ghisler.ch/wiki/index.php/AutoHotkey

This is a script to change panel directories by WM_COPYDATA. You can also leave v_LeftDir or v_RightDir empty if you wanna change one side only. S and T parameter are equivalent to /S and /T parameter in section 4a of TC help file. You can leave out both or one of them too.

Code: Select all

;*** config start
v_LeftDir := "%windir%"
v_RightDir := "%programfiles%"
v_Parameter := "ST"
;*** config end
ChangeDir(v_LeftDir, v_RightDir, v_Parameter)

ChangeDir(ByRef v_LeftDir, ByRef v_RightDir, ByRef v_Parameter)
{
  v_Dirs := v_LeftDir . Chr(13) . v_RightDir
  VarSetCapacity(CopyDataStruct, 12, 0)
  NumPut(Asc("C"), CopyDataStruct, 0)
  NumPut(Asc("D"), CopyDataStruct, 1)
  NumPut(StrLen(v_Dirs)+4, CopyDataStruct, 4)
  NumPut(&v_Dirs, CopyDataStruct, 8)
  Loop, Parse, v_Parameter
    NumPut(Asc(A_LoopField), v_Dirs, StrLen(v_Dirs) + A_Index)
  SendMessage, 0x4A, 0, &CopyDataStruct,, ahk_class TTOTAL_CMD
  VarSetCapacity(CopyDataStruct, 0)
}
TC internal commands are sent like that:

Code: Select all

PostMessage, 1075, %number_of_command%
Available commands and their numbers are stored in file TOTALCMD.INC. There also is a script from SanskritFritz in the wiki which parses that file.

Sending user commands is possible too:

Code: Select all

;*** config start
v_UserCommand := "em_BlaBla"
;*** config end
SendUserCommand(v_UserCommand)

SendUserCommand(ByRef v_UserCommand)
{
  VarSetCapacity(CopyDataStruct, 12, 0)
  NumPut(Asc("E"), CopyDataStruct, 0)
  NumPut(Asc("M"), CopyDataStruct, 1)
  NumPut(StrLen(v_UserCommand)+1, CopyDataStruct, 4)
  NumPut(&v_UserCommand, CopyDataStruct, 8)
  SendMessage, 0x4A, 0, &CopyDataStruct,, ahk_class TTOTAL_CMD
  VarSetCapacity(CopyDataStruct, 0)
}
Icfu
This account is for sale
Ernest de Vroome
Junior Member
Junior Member
Posts: 3
Joined: 2007-10-01, 22:24 UTC
Location: Utrecht, Holland

Post by *Ernest de Vroome »

Dear Icfu,

Thanks for your detailed advice. Unfortunately, I understand just over half of it. :oops: I tried to use the last part, which I understand most (although, why all those comma’s and symbols “0x4A, 0, &” etc., are they all essential?).

I downloaded the “AutoHotKey”-program you were referring to, and created the following “AutoHotKey”-script:
v_UserCommand := "em_usercmd1"
SendUserCommand(v_UserCommand)
SendUserCommand(ByRef v_UserCommand)
{
VarSetCapacity(CopyDataStruct, 12, 0)
NumPut(Asc("E"), CopyDataStruct, 0)
NumPut(Asc("M"), CopyDataStruct, 1)
NumPut(StrLen(v_UserCommand)+1, CopyDataStruct, 4)
NumPut(&v_UserCommand , CopyDataStruct, 8 )
SendMessage, 0x4A, 0, &CopyDataStruct,, ahk_class TTOTAL_CMD
VarSetCapacity(CopyDataStruct, 0)
}

v_UserCommand := "em_usercmd2"
{
VarSetCapacity(CopyDataStruct, 12, 0)
NumPut(Asc("E"), CopyDataStruct, 0)
NumPut(Asc("M"), CopyDataStruct, 1)
NumPut(StrLen(v_UserCommand)+1, CopyDataStruct, 4)
NumPut(&v_UserCommand , CopyDataStruct, 8 )
SendMessage, 0x4A, 0, &CopyDataStruct,, ahk_class TTOTAL_CMD
VarSetCapacity(CopyDataStruct, 0)
}
Where “em_usercmd1” is a “named” and stored synchronization command, and “em_usercmd2” another (finally about 20).

I compiled the script (menu on right mouse-button), and also created a button in TC “pointing” at the “exe”-file resulting from the compilation. Pressing that button successfully first loaded the first synchronization screen, and after closing the first, the second appeared (and so on, finally). That is just what I wanted, thanks. After closing the last screen, however, TC comes up with an error-pop-up saying: “Access violation at address 004C2E7C. Read of address 0000001C8. Please report this error to the author…”, and the latter is what I am now doing in this posting.

In short, two questions:
Is that “error-pop-up” avoidable, and how?
Were the steps I took the right ones, or do you (or someone else) have a much easier way to execute several (in fact: all) “named” and stored synchronizations one after the other? [In fact, actually loading the directories in the left/right panels is not necessary and can be left out of the intended script].

Thanks in advance for any possible answer, Ernest
icfu
Power Member
Power Member
Posts: 6052
Joined: 2003-09-10, 18:33 UTC

Post by *icfu »

The example functions were meant as a start for you, not as a fully functional way to remote control the sync tool. You don't need to understand what the functions do (the code written in square brackets), just call and use them. 0x4a is WM_COPYDATA API call...

If I start answering questions like "are all those commas really needed", this will end in a never-ending AHK lesson, this is completely out of my interest. For specific help regarding AHK I recommend you to join the AHK forum.

You will have to examine the AHK help file yourself and learn some basics first. Read the chapters about functions and their usage (you don't need to repeat the function content again and again, you only need to write it down once in your script and then call it for every user command you wanna send), chapter about loops, maybe use sleep command to prevent the error given by TC, just a guess...

Personally I would not script the sync tool but use a command line utility to do mass syncing, like Xcopy, XXCOPY, Robocopy, etc... as it's much more reliable regarding input errors.

Good luck!

Icfu
This account is for sale
th_alton
Junior Member
Junior Member
Posts: 5
Joined: 2007-10-02, 20:28 UTC

Post by *th_alton »

It would be great if simple macros could be implemented in TC.

I would love to be able to call several TC commands with one hotkey without having to use an external program.

Is this something that will be implemented in the future?
Ernest de Vroome
Junior Member
Junior Member
Posts: 3
Joined: 2007-10-01, 22:24 UTC
Location: Utrecht, Holland

Post by *Ernest de Vroome »

Dear Icfu,

Seven days ago I never heard of AHK, and I am not intending to get familiar with it either. It appears to be for nerds-only anyway, and I do not have time to receive ‘endless’ AHK lessons. Using ‘(x)(x)(robo)copy’ would be back to ‘dos’. Then I might as well use ‘dir’ instead of TC.

So I ‘googled’ somewhat on the term ‘file synchronization’, and found that for instance the free program ‘Allway Sync’ (http://www.allwaysync.com/) does exactly what I meant. ‘Named’ synchronizations are called ‘jobs’, there, and I quote the manual: ‘You can synchronize more than one job at a time (Select the menu item ‘Synchronize all’)’, just with one single right-mouse-click.

It should not be too difficult for Christian to add to the already existing TC-menu on the button called: ‘Open list of sync directories+options’, the option: ‘Load and execute entire list simultaneously’, so in fact just under the already existing option in TC: ‘Add current directories and settings to list’ (i.e. list of ‘named’ and stored synchronizations). So anxiously waiting for the next revision of TC to see if this or something similar is implemented...
icfu
Power Member
Power Member
Posts: 6052
Joined: 2003-09-10, 18:33 UTC

Post by *icfu »

Seven days ago I never heard of AHK, and I am not intending to get familiar with it either.
Why do you pretend to be interested then? You have started to write an own script and have asked for more input in your second posting in this thread.
It appears to be for nerds-only anyway, and I do not have time to receive ‘endless’ AHK lessons.
That's fine for me.
Using ‘(x)(x)(robo)copy’ would be back to ‘dos’. Then I might as well use ‘dir’ instead of TC.
There is a difference between using a command line and using DOS.
It doesn't make much sense to use GUI applications for tasks that have to be repeated regularly and syncing always the same 20 directories is a perfect reason to do work once – write a batch or a script – and then executing it knowing that it will work flawlessly without watching it.
It should not be too difficult for Christian to add to the already existing TC-menu on the button called: ‘Open list of sync directories+options’, the option: ‘Load and execute entire list simultaneously’, so in fact just under the already existing option in TC: ‘Add current directories and settings to list’ (i.e. list of ‘named’ and stored synchronizations). So anxiously waiting for the next revision of TC to see if this or something similar is implemented...
Yes, of course it's "no problem at all", to implement this and that in TC, this is maybe why you are the first one in the past 14 years who has asked ghisler to implement macro capabilities in TC...

You might be interested to hear that whenever someone asks for scripting abilities in TC, ghisler recommends AHK meanwhile. You are free to wait for whatever feature you like, maybe you are lucky and will win the jackpot in the next TC version, who knows.

Sorry for trying to help you. I see that it was worth the efforts, as usual. :evil:

Icfu
This account is for sale
User avatar
Ennovy
Junior Member
Junior Member
Posts: 31
Joined: 2007-06-14, 09:49 UTC
Location: The Netherlands
Contact:

Post by *Ennovy »

2icfu
Sorry for trying to help you
Don't be sorry, you are a great help to a lot of people :!:

I don't post very often in this forum, but read it every day. Since then I learned very much about all the wonderful features of TC.

So please, don't let this discourage you :wink:
#134575 Personal licence
Total Commander 9
Windows 10 64bit

Tough times never last, tough people do!
User avatar
eugensyl
Power Member
Power Member
Posts: 564
Joined: 2004-06-03, 18:27 UTC
Location: România
Contact:

Re: Scripts/macro’s/menu’s with more than one command?

Post by *eugensyl »

Ernest de Vroome wrote:Is it possible in TC to create a script/macro/menu to do several "things" one after the other, all just by pressing the same user-defined button only once?
... Ernest
Try TC Multiple Commands (TCMC) - a small utility which send more than one command to TC.
My Best Wishes,

Eugen
Post Reply