If-Endif                                                                   Example

If you want to perform certain actions only if certain window exist or does not exist then you can use conditional If-Endif commands.

How to wait for a condition to be true?

  1. Let's say you want to perform some action only if a window exists. You know it might take anytime between 5 seconds to 5 minutes for that window to come up.
  2. Obviously, you would not like to wait for 5 minutes if the window comes up in 30 seconds.
  3. Workspace Macro Pro takes care of this for you.
  4. In the textbox in the If command, specify the maximum time (in seconds) up to which you like to wait for the window to appear. In this case 5 minutes i.e. 300 seconds.
  5. Workspace Macro Pro will keep on checking for the window up to 300 seconds and as soon as the window appears, will execute actions within the conditional commands. So in this case, it will wait only 30 seconds and then performs the actions.
  6. If you leave the textbox empty or provide 0 then Workspace Macro Pro checks the condition right away and if it is met it will execute the actions otherwise it will skip those actions and proceed to actions after Endif.

Example 1:To close notepad window if open.

  1. Open the Macro Editor from Tools -> Macro Editor.
  2. Double click on the 'If' command.
  3. Select the option 'Window exists'.
  4. Make sure that 'Untitled - Notepad' is already open.
  5. Click on the 'Refresh' button.
  6. Select the title 'Untitled - Notepad' from the list.
  7. Click on 'Save' button.
  8. Insert the 'Close Window' command in between 'If - End if' statements.

Example 2:Search for a record, if found perform different actions

Often you want to perform a search for an item, a word or a record in your application. If found you want to perform some actions, and if not, perform some other actions.

  1. Search for a item, a word or a record that doesn't exist so that you see a window that says 'Not Found'.
  2. Open the Macro Editor from Tools -> Macro Editor.
  3. Double click on the 'If' command.
  4. Select the option 'Window exists'.
  5. Select the Not Found window title from the list.
  6. Click on 'Save' button.
  7. Insert the actions you want to perform between 'If - End if' statements.