Classic Computer Magazine Archive COMPUTE! ISSUE 137 / JANUARY 1992 / PAGE S18

How to create keyboard macros with DOS 5.0. (MS-DOS Featuring DOS 5.0)
by Tony Roberts

A few years back, every computer owner needed a good memory-resident keyboardmacro program, since few applications of that era provided their own macro capabilities. (A macro is a set of commands that can be carried out by issuing a single command or by pressing a specified key combination.)

Today, however, stand-alone macro programs are hard to find. Nearly all major commercial software can handle macros.

Your word processing program, your spreadsheet program, and your database manager all probably have macro capabilities.

Stuck in a Groove

The trick to using keyboard macros is in identifying repetitive processes. Typing the name and address of your business, for example, is a repetitive process.

Your word processing program probably has some facility for capturing the keystrokes in your business name and replaying them quickly, perhaps at the touch of a function key.

In addition to capturing and replaying simple text, macros can turn complicated procedures into one-command jobs. Let's say that you're writing a report about a new widget and you want to boldface the product's name throughout.

You create a macro that moves to the top of the file, uses the search command to locate the word widget, issues the commands to place that word in boldface, andthen repeats the process through the rest of the file.

This macro can do in seconds what would take several minutes to do by hand. This may seem like small change, but it leads to big benefits.

If you're comfortable working with small macros, you'll be ready to whip up a monster macro when you need to completely reformat a 50-page report in a short afternoon.

Similarly, you can save time by creating macros to help pull the monthly reports from your spreadsheets and databases. It's a matter of identifying repeated actions and boiling them down to a few keystrokes.

Macromania

With the recent release of MS-DOS 5.0, we now have the ability to create macros from the command line. The DOSKEY program, known mostly as a command line retriever, also includes a macro function.

These DOS macros act very much like batch files, but they're called from memory rather than from disk.

DOSKEY macros are limited to 127 characters, and they can't include GOTO commands or call other macros.

Despite these limitations, macros can be handy, especially if you're working on a system with a slow--or nonexistent--hard disk. Your macros occupy fast RAM and act like extensions of the operating system.

Here's an example of how to create a DOSKEY macro.

This creates a macro called NEWDIR, which makes a new subdirectory and moves to it in one fell swoop. To use this new command, type NEWDIR dirname (where dirname is the name of the directory you want to create).

Like batch files, DOSKEY macros permit the use of replaceable parameters. In macros, however, the parameters are designated with dollar signs rather than percent signs.

Note that unlike batch files, DOSKEY macro commands are strung together on a single line. The $T is used as a command separator.

Since DOSKEY macros can be defined in a batch file, you may want to include your favorite macros in your AUTOEXEC.BAT file so they're always available.

If you run any utility programs that require several command line parameters, you can simplify these commands into short, easy-to-remember macros.

DOSKEY macros also are useful for those one-day projects when you have to repeat certain commands only for that day.

You could write a batch file, except that in this case, you won't ever need it again. Because a DOSKEY macro is memory-based, it disappears when you shut the system down.