May 7, 2010

Run All Macros in a Folder/Group

Filed under: Automation,Scripting — Marcus Tettmar @ 3:26 pm

Someone asked me today how to run all macros found in a folder. This simple script will run all macros it finds in its own folder in turn:

GetFileList>%SCRIPT_DIR%\*.scp,MacroFiles
Separate>MacroFiles,;,Macros
If>Macros_count>0
  Let>k=0
  Repeat>k
    Let>k=k+1
    Let>this_macro=Macros_%k%
    If>this_macro<>SCRIPT_FILE
      Macro>this_macro
    Endif
  Until>k=Macros_count
Endif

Note the check to make sure it doesn’t run itself!

This could be useful where you want a quick way to schedule a series of macros. Schedule this script and then all you need to do to add another to the schedule is to drop it into the same folder (or macro group).

For a bit more control consider naming each macro with a numeric prefix and then sort the array to determine the order in which they are run. Version 12 (currently in beta) has a built in ArraySort function. Or use this QuickSort algorithm.