Custom event triggers 101. Make an image start a macro

Example scripts and tips (replaces Old Scripts & Tips archive)

Moderators: Dorian (MJT support), JRL, Phil Pendlebury

Post Reply
User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1348
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Custom event triggers 101. Make an image start a macro

Post by Dorian (MJT support) » Wed Dec 05, 2012 8:20 pm

I've recently discovered the power of custom event triggers, and thought I'd share this little script.

The principal is simple. Let's say you wish to run Macro A when a certain image is visible on screen. You'd simply write a second macro, which we'll call Trigger, which looks for the image.

Then all you need do to is go into custom event triggers and tell Macro A to use Trigger.

We have to follow a few simple rules, so here's an example.
------------
I used the Image Capture Tool (found in the script editor, under Tools) to grab one of the buttons in Audacity. If my trigger sees that button, my macro triggers.

Macro saved as Trigger.scp:

Code: Select all

SRT>Trigger
FindImagePos>c:\audacity.bmp,SCREEN,0,1,X,Y,NumFound
If>NumFound>0
   Let>MACRO_RESULT=TRUE
   Else
   Let>MACRO_RESULT=FALSE
Endif

END>Trigger
 
SRT>Reset
FindImagePos>c:\audacity.bmp,SCREEN,0,1,X,Y,NumFound
If>NumFound>0
   Let>MACRO_RESULT=FALSE
 Else
   Let>MACRO_RESULT=TRUE
Endif
END>Reset
Macro A:

Code: Select all

messagemodal>I see it!
So now we have our two Macros, we can set up the custom event trigger.

Open Macro A and go to the Trigger tab. Under "trigger type" select "Custom Event (Script)"

Using the browse button, browse to your script directory and select "Trigger.scp". Click "open", and save Macro A.

The next time your image is visible on screen, Macro A will burst into life!
Yes, we have a Custom Scripting Service. Message me or go here

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts