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!

PTFB’s Visual Trigger Up Close

It’s time to take a closer look at one of the major new features in PTFB Pro version 5 : Visual Triggers.

Simply put, they allow PTFB to react to a change on screen that is visible to the eye, but is otherwise not detectable. Examples include a change in color, in wording, or in a graphic.  Visual change triggers are available for single clicks / presses and for all of PTFB’s macro types, including”ProgMons” which are used to handle launching, suppression and automatic restarting of other programs on your Windows PC.

To use the new trigger type, you need to open up your macro for editing (just double-click it on PTFB Pro’s main screen) then switch to the Triggers tab. The option you’re looking for is the checkbox labelled “Visual Change” in the top left of the “Other Triggers” section:

Visual Change - Triggers Page

Tick this new trigger type or press the “Change Settings…” button next to it to open up a new screen where you can set the specifics: what part of the screen you want to monitor, and what kind of changes will be enough to cause your macro to run. Let’s take a look at that settings dialog now:

Trigger on Visual Change - Settings

The first section of this dialog defines which part of the screen should be monitored for changes; you do this by press the button marked “Choose Area”. Your mouse cursor will change to a little grey-bordered box; simply move that box over the target area and click the left mouse button to select it (or click the right mouse button / press the “Esc” key to abort). For performance reasons the largest area you can monitor is a 32 x 32 pixel square; you can narrow this to a smaller area (16 x 16 or 8 x 8) at any point if you wish. PTFB Pro will indicate whether the area you’ve chosen is a part of the screen as a whole, or a part of your target window if you’re editing a single-press item or window-based macro. At the instant you click to set the area, PTFB Pro takes a snapshot of the region as it is right now. You get to choose if and how this snapshot will be used in the section titled “Conditions For Trigger”.

The first choice in the Conditions section is whether to react to a difference or a match; the “Match” case is useful when the monitored area changes routinely but you only want the press or macro to run when it’s a reasonable match to the snapshot you just recorded.

Next – if you’ve chosen to trigger on “Difference” – you can choose whether comparisons will be made against the fixed snapshot you made earlier, or against a so-called “Dynamic” snapshot. If you want PTFB Pro to react each and every time the monitored area changes then you should choose “Dynamic”, otherwise just go for the “Fixed snapshot” option.

Finally there’s a slider that lets you fine-tune the sensitivity of the visual trigger. The effect of this depends on whether you previously chose to trigger on a “Difference” or a “Match”. When looking for a difference, the left hand side of the slider represents maximum sensitivity; PTFB Pro will run the macro in response to any detectable change. As you move the slider to the right, PTFB Pro requires a more substantial change before the macro runs. The slider effect for “Match” works the other way around; the left hand side requires an almost exact match with the snapshot, but as you move it to the right, an increasingly less perfect match will be enough to trigger your macro.

I should take a moment here to note the link between the effect of the slider control and the area size that you choose. A small change in the largest (32 x 32 pixel) area size might only rack up a difference value of say 8%. However, if you drop that to the smallest area size (8 x 8) then that same small change becomes more significant. Remember that phrase “small fish in a big pond” : the same principal applies here.

To make it easy to tune all these settings and ensure that you’ll get the effect you want, the Visual Change Settings screen has a button marked “Test Now”. Press it, and PTFB Pro will tell you exactly how much of a change it sees, and whether it would be enough to trigger your macro.


So that’s the lowdown on the new Visual Change trigger-type in PTFB Pro; the next post will focus on some of the other new features in version 5. Don’t forget you can try PTFB Pro right now by downloading the free 30-day trial.

 

PTFB Pro Version 5 Adds Visual Triggers and Command Line Control

PTFB Pro has just received a major update and its brought a lot of new features that our customers have been asking for, including:

1) Visual Triggers

Your macros can now fire automatically when a change is seen in a portion of the target window or the screen. It’s a huge new addition for PTFB, allowing it to react to things that we as humans can readily see (such as changes to text, graphics and color) but which previously it was unable to detect. This new trigger can be fine-tuned in a number of ways, so you can have your macros fire exactly when you need them to.

2) Greatly improved command line control for better integration with Powershell and other script shells

Ever since version 3 it’s been possible to trigger macros via the command line, but version 5 has expanded on this considerably. From the command line you can now:

  • Enable/Disable PTFB Pro as a whole, enable/disable a list of macros
  • Trigger any number of macros AND pass named parameters through to be used by v5’s newly extended macro actions
  • Properly synchronise command line actions thanks to the new /WAIT command line directive

3) Control the clipboard

A new “Set Clipboard” macro action has been added which lets you load literal text, the contents of text files, and even files themselves into the Windows clipboard, for use in subsequent paste operations. This action can take a command line parameter, so you can pass in clipboard content from a script or command shell such as Powershell.

4) Track when a macro was last used, and easily archive little-used macros

I’m not afraid to admit that I have mild hoarding tendencies; when I create a macro or single press for a specific job I rarely delete it. The result is that over time my copies of PTFB Pro have filled up with lots of items that were used heavily for a short time, but have layed dormant ever since. PTFB Pro dutifully loads them into memory and checks them multiple times each second to see if they’re ready to fire automatically; remove them, and PTFB Pro becomes just a little leaner and faster to respond. Version 5 now tracks the most recent usage date/time, and can use this information to disable unused items and/or move them to a specific tab.

5) Instantly test your settings on the “Identifying the Target” page

There can be a learning curve for people who are tailoring a single-press or window-based macro so that it keeps firing even when the target window changes. Version 5 takes the guesswork out of this process by adding a “View Matches” button to the target identification page; press that button, and PTFB Pro will show you exactly which windows match your settings.


I’ll take a closer look at these new features in later posts, but you can try them out yourself right now by getting your copy of v5 from our download page: http://www.ptfbpro.com/download.shtml

Note that because this is a major upgrade it’s only free to people who bought v4 on or after June 1st 2016 (about 90 days prior to the release of v5). Anyone who bought before this date can purchase an upgrade license at a 50% discount. Please visit our upgrades page for more details or just send an email to support@ptfbpro.com and we’ll send you a free license / discount purchase link  – whichever is appropriate.