Making your macros intelligent, with If, Else, and Endif

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

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

Making your macros intelligent, with If, Else, and Endif

Post by Dorian (MJT support) » Wed Oct 23, 2013 1:16 am

I'm often asked how to make a macro behave differently based on certain criteria. The power and flexibility of Macro Scheduler makes this an easy task.

There are hundreds of different reasons you might want to do this. Maybe it's dependent on :
  • The answer to a question.
    The success/failure of an operation.
    The contents of a file.
    If a file or folder exists.
    If a certain mathematical goal is reached (e.g. if>count=100).
    If a certain image is visible on the screen.
    If the value of a cell in an Excel spreadsheet matches your requirement.
    If an email was/wasn't successfully sent.
    If a value on a web page matches your criteria.
    The day/date/time or year
That's just a handful of the many hundreds of variables we can check, but the basic rules of IF, Else, and Endif are always the same.

Let's use asking a simple yes/no question as an example. We simply tell the macro something like this :

Ask a yes/no question

If the answer is yes
Do this

If the answer is no
Do that.


It's that simple! So, how do we put that into simple Macro Scheduler language? Here's how :

Code: Select all

//ask a yes/no question
Ask>Do you like brussel sprouts?,question

//depending on the answer given, the macro will execute *one* of the two lines below, then continue on with the rest of the script
If>%question%=YES
    messagemodal>I agree, but let's keep it our secret
Else
    messagemodal>Right.  They're ghastly
Endif

//you can abbreviate messagemodal to mdl
mdl>OK, on with the rest of this script.
Without all the comments :

Code: Select all

Ask>Do you like brussel sprouts?,question

If>%question%=YES
    messagemodal>I agree, but let's keep it our secret
Else
    messagemodal>Right.  They're ghastly
Endif

mdl>OK, on with the rest of this script.

So, in short, we are doing this :

Code: Select all

If>your condition is/isn't met
  //do this

//or else
Else

  //do that

Endif
"Else", is optional. If you don't need an "else", just leave it out. All you need is the If and Endif. This is for if we just need to tell a macro to perform a certain action based on your criteria, but not an alternative action if the criteria is not met.

Code: Select all

IF>your condition is met
  //This line only executes if the condition is met, otherwise it's ignored
Endif
Helpfile links for your reference :

Ask
If
Messagemodal

Questions? Reply to this thread. Our support team and our community are always happy to help. :D
Yes, we have a Custom Scripting Service. Message me or go here

User avatar
Rain
Automation Wizard
Posts: 550
Joined: Tue Aug 09, 2005 5:02 pm
Contact:

Post by Rain » Mon Nov 04, 2013 1:02 pm

Nice Tut, Parsnip...I'm sue someone will find this useful.

+Rep :D

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