Running Macros and Passing Parameters via Powershell / Command Line

Last time I looked at the new trigger in PTFB Pro v5 that can react to changes in color, text, and even graphics. In this post, I’ll concentrate on new facilities that version 5 brings via the command line; they’re useful enough on their own, but they’re especially helpful if you want drive PTFB Pro from a powerful scripting engine such as Powershell.

Command Line Control of PTFB

Enable/Disable Macros or PTFB Pro as a whole

The /ENABLE or /DISABLE directives can be used to enable or disable either PTFB Pro as a whole, or a specific set of macros / press items. If your goal is to enable/disable macros, just specify the four-digit macro IDs in a space-separated list (you can get the IDs from the Triggers page for each of the items). Here are some examples:

"C:\Program Files (x86)\Technology Lighthouse\PTFB Pro\PTFBPro.exe" /ENABLE
"C:\Program Files (x86)\Technology Lighthouse\PTFB Pro\PTFBPro.exe" /DISABLE 1BF0 5C33 7EA0

The first line above (re) enables PTFB Pro, while the second disables three specific macros, so they can no longer run automatically.

Run a list of macros / presses

PTFB Pro v4 was able to launch up to two macros from the command line; in version 5 there’s no limit to the number of macros / presses that can be run, and they’ll be run in the order given. Just include the macro IDs in a space-separated list like so:

"C:\Program Files (x86)\Technology Lighthouse\PTFB Pro\PTFBPro.exe" 1AB0 83CB 2FF0

Waiting for completion

Sometimes when you’re running PTFB Pro from a script it’s handy to make the script wait until the actions you’ve requested have actually completed. That is now possible in version 5 thanks to the “/WAIT” directive. To use it, just include it as the first thing on the command line right after the path to PTFB:

"C:\Program Files (x86)\Technology Lighthouse\PTFB Pro\PTFBPro.exe" /WAIT 1AB0 83CB 2FF0

In the above example, the command will only return when the final macro (ID 2FF0) has finished executing. If you omit the “/WAIT” directive, the command will return almost immediately, likely before any of the macros have run to completion.

Parameters

Some of PTFB Pro’s macro actions now take optional named parameters, and these parameters are supplied via the command line:
"C:\Program Files (x86)\Technology Lighthouse\PTFB Pro\PTFBPro.exe" 1AB0 -param10 "3" -param2 "My Text" 83CB 2FF0

In the above example, the macro with ID 1AB0 will be executed and the values 3 and My text will be provided as parameter#10 and parameter#2 respectively to any actions in the macro that use those named parameters. The macros with IDs 83CB and 2FF0 will then be executed, but they will run without any parameter values.

So, which actions can take parameters? Currently the list includes: Run Item, Run Executable, Enable Item Temporarily, Repeat Loop, Switch To Prog and Set Clipboard. That last action – Set Clipboard – is also new to PTFB Pro version 5; it allows you to load the Windows clipboard with one of the following:

  • literal text
  • the contents of a nominated text file
  • one or more file paths (file objects)

If you’re a bit of a Powershell script addict, I’m sure you’re already realising just how useful the new parameterized control of PTFB is going to be. Even if you’re not much of a scripter now, be aware that the facilities are there for if you should need them in the future, and they’re due to be extended further in subsequent updates to v5!