Conditional execution in Macros!!!
Posted: Fri Mar 15, 2002 10:46 am
It's possible to execute a task based on the existence of a particular text pattern. Unfortunately there can only be one per macro.
This trick works because of the feature which causes a macro to abort when a search fails.
To use this feature, simply mark the area which is to be scanned for the text pattern using keyboard commands (mouse movements are not recorded) and use the find command (F5). After the find has been executed (the text need not be found during the recording), continue with the commands which are to be conditionally executed, end and save the macro.
There are limitations:
1. As stated, restrict yourself to keyboard commands, e.g. go to (ctrl-g), because mouse movements are not recorded.
2. Putting multiple conditional macros in one macro, if it works, which I have not successfully done, have major drawbacks. First, the macros are not referenced by name, rather, their bodies are copied into the main macro so you cannot modify a sub-macro and have that change reflected in the main macro. Second, as a result of the first problem, if it works, which I have reason to doubt, the first search to fail aborts all subsequent execution.
3. There are a number of functions unavailable during macro recording:
- preferences
- macro recording (joke, joke!)
- compare files
- spelling
- find in files
- undo
- close
- close all
and possibly some more.
So this isn't really so earth shaking but it might prove useful here and there until a real macro editor is implemented.
Have fun.
This trick works because of the feature which causes a macro to abort when a search fails.
To use this feature, simply mark the area which is to be scanned for the text pattern using keyboard commands (mouse movements are not recorded) and use the find command (F5). After the find has been executed (the text need not be found during the recording), continue with the commands which are to be conditionally executed, end and save the macro.
There are limitations:
1. As stated, restrict yourself to keyboard commands, e.g. go to (ctrl-g), because mouse movements are not recorded.
2. Putting multiple conditional macros in one macro, if it works, which I have not successfully done, have major drawbacks. First, the macros are not referenced by name, rather, their bodies are copied into the main macro so you cannot modify a sub-macro and have that change reflected in the main macro. Second, as a result of the first problem, if it works, which I have reason to doubt, the first search to fail aborts all subsequent execution.
3. There are a number of functions unavailable during macro recording:
- preferences
- macro recording (joke, joke!)
- compare files
- spelling
- find in files
- undo
- close
- close all
and possibly some more.
So this isn't really so earth shaking but it might prove useful here and there until a real macro editor is implemented.
Have fun.