May 9, 2014

Macro Recorder vs Code Wizards

Filed under: — Marcus Tettmar @ 11:59 am

Macro Scheduler includes a Macro Recorder. In the early days it didn’t have one. In fact we resisted adding one at first.

We didn’t want to add a macro recorder because we believe their power is limited and the reality is that at some point you have to edit the code it produces. A macro recorder records an entire sequence. If you want to alter a part of that sequence in the middle you can’t really do that with a macro recorder. You need to edit the code.

More importantly there’s a limit to how clever a macro recorder can be. To work everywhere, in every app, it can only really monitor your keystrokes and mouse moves. Our Macro Recorder also monitors window positions and sizes, and creates code that sets the window positions and sizes to be the same at runtime as they were at record time, to try and eliminate issues where positions change between design time and run time.

Even then window names can be different at run time, and for most business processes the data you are entering is going to be different next time around – you are probably going to want to loop the input to work for different records. So you’re going to have to edit the code that was produced. Sure, this can be done – you can edit the code our Macro Recorder produces, but if you’re going to do that then maybe it would have been easier to write the code in the first place?

Also, we had experience of macro recorders and writing scripts manually. We knew that we got smaller, tighter, more reliable macros when coding manually. But rather than leave our customers staring at a blank white editor window we provided wizards and code builders.

Eventually we did add a macro recorder mostly due to overwhelming demand. See, IMO people think they need a macro recorder, but really don’t. And because of that we needed one commercially. Without one many people wouldn’t have given us a look-in. I am pretty certain that most people end up not using it and soon move on to more flexible methods.

I believe we offer something just as easy but far more powerful than macro recorders. Right from the start Macro Scheduler had “code builders”. We didn’t call them that back then but to output script code you could choose from drop downs and so on. Nowadays, of course, we offer a full featured script editor, but every function also has a code builder and there are wizards for the slightly more tricky routines that require a bit more code, or where you would usually need to poke under the hood of an app.

These wizards are incredibly powerful. They allow you to build up macros without any programming skills. They allow experts who do have programming knowledge to build code quickly. They allow you to address specific parts of a routine in isolation, whereas a macro recorder generally requires you to perform a number of steps with no way to jump into the middle of a routine.

Just watch these videos to see how easy it is to build up a script to automate the control of applications and web apps using the wizards:

How to use Macro Scheduler’s Image Recognition Functions
Using Macro Scheduler’s Find Object Wizard
Using Macro Scheduler’s Find IE Element Wizard

Of course, the macro recorder has it’s uses. For basic stuff and for complete newcomers who just want to automate a few keystrokes or mouse actions it might make sense. There’s also a keyboard wizard, and a mouse wizard which are effectively just mini recorders, which are useful when you want to insert small blocks of keyboard/mouse events into a script.

However, for anything robust and dynamic the wizards are far more powerful yet just as easy to use.

Consider a scenario where you need to open the most recent Excel file in a folder, and grab some data from it and input that into another window. How would you record finding the latest file in the folder and opening it in Excel? Believe it or not I’ve seen people do this by automating mouse clicks – they open Windows Explorer, click on the columns to sort, click on the first item – and they make all kinds of assumptions such as the size of the window, the original sort order and so on. Then they proceed to mouse click in Excel.

When I see people do this, first I scream, and then, when I’ve calmed down, I show them how to do the same using a few basic commands, using the code builders and some wizards.

To find the newest file in a folder? There’s one line of code for that, using the GetNewestFile command. Not sure how to use it? Open up the code builder and it will tell you what you need to enter – the folder to look in and a variable to store the result in.

That’s one line. Instead of lots of crazy mouse clicks. Next, we can open the XLS file up with one XLOpen line. There’s even a sample macro which ships along with an example XLS file which shows this in action. And a code builder. Next use XLGetCell to get the data. Right, so that’s three lines of code instead of dozens of mouse clicks and waits. Finally use the send keys wizard, or find object wizard or code builders to send the data into the target app.

It’s really no more difficult than using the macro recorder and probably quicker. And you get shorter, tidier, more reliable code that is easier to understand.

So for me, wizards win out every time. I believe wizards provide the simplicity of macro recorders but with the power and reliability of manually written code.