Save Coding Time with TextPad Macros
by Dale Mead

HTML coding, especially for cascading style sheets, frequently requires repetitive keystrokes. For example, in Case 2 of Tutorial 7, you're required to type seven lines of code in 18 separate pages. The logical way to do so is to type each line once, copy it and then paste it into each sheet. But you still must maneuver to the proper place in each document before pasting. This can be done with the mouse, but often it also can be done mostly or entirely with keystrokes.

Fortunately, TextPad has a powerful feature that cuts time for such tasks to a fraction of the time for the obvious method. The feature is macros; you'll see a menu label for them at the top of the TextPad work window. Macros consist of TextPad recording a series of keystrokes; then it runs the entire sequence automatically when you press a single keystroke combination. (For more on learning keystroke shortcuts in Windows, see below.)

To learn all about TextPad macros, look them up in TextPad Help starting with Macro: Overview. Following is an example to illustrate their power.

In Tutorial 7, Case 2, step 3 directs you to create a style sheet and "link each of the 18 Web pages to the style sheet. You may want to use copy and paste to save typing and reduce the possibility of errors." You have to insert a single line of code into 18 documents. With a macro, you can do much more than cut and paste. To experience it, do step 1 of Case 2 (p 7.63). Then try these steps to complete step 3. (NOTE: The process assumes the 18 files created in step 1 have not been altered or edited beyond the instructions.)

1. Open all 18 documents, h01.htm through h18.htm. Press Ctrl-O, select all of the files (if they're interspersed, click on each while holding down the Ctrl key), and press Return. All will open in the listed order, so h18.htm is the last and active file.

2. In h18.htm, place the cursor before the </head> tag and press Return and the Up arrow to create a blank line above the </head> tag and move your insertion point to it. This is where you'll write the link tag that must go in all the files; this is also where you will paste it in all the other files.

3. Type the tag: <link href="willet.css" rel="stylesheet" type="text/css">

4. Save the change with Ctrl-S.

5. Select the entire line, including the invisible line break at the end. (The surest way is to place the insertion cursor at the left of the line; then drag the mouse straight down, or hold down the Shift key and press the Down arrow.)

6. Copy the selected line; the keystroke to do this is Ctrl-C.

7. Move to the next file, h17.htm (don't close h18.htm); the keystroke to do this is Ctrl-F6.

8. The cursor should be at the top left corner of the text when you first go into the file. Place it in front of the </head> tag as in step 2.

9. Now you will record all your keystrokes until you end up in the same place in the next open file, h16.htm. To start recording, press Ctrl-Shift-R.

10. Type the following keystrokes:
Ctrl-V (to paste the link tag line in the file)
Ctrl-S (to save the change) (If the Register window appears, close it as usual and continue.)
Ctrl-F6 (to go to the next open file, h16.htm)
Down arrow, 3 times (to get to the </head> tag)

11. Press Ctrl-Shift-R again to stop recording. You now have captured your macro. You will be asked whether you want to save the macro. Choose No.

12. Press Ctrl-R to run the macro. TextPad will add the link tag line and move to the right position in h15.htm.

13. Keep pressing Ctrl-R until you have copied the link tag line in all 18 files. Don't forget to stop! Ctrl-F6 will keep recycling through all open files indefinitely; so if you get carried away, you'll begin inserting the link line twice.

Note that you did not use your mouse while recording. TextPad's macro function does not record mouse movements, which makes it much more reliable than macro programs that do. However, it lets you pause in the recording to make unrecorded moves (such as pointing and clicking with the mouse) before resuming the recorded keystrokes.

The macro function also comes in very handy for Case 2 step 2, where you have to place six <div> and </div> tags in all 18 files (which is why you benefit from leaving the files open). They're more complicated than the above example, but your ingenuity will reward you with perhaps 10-20 minutes of work completed in less than five minutes.


Finding Keystroke Shortcuts

Most Windows applications let you use keystroke shortcuts instead of point-and-click mouse movements for virtually every action on every menu. The most universal functions, such as copying, pasting and printing, involve the Ctrl key combined with another key. The shortcuts may be listed when you open the menu for each category at the top of the TextPad work window.

But Windows covers just about all the functions by letting you hold down the Alt button while pressing a sequence of other keys. To open a file, for example, you can press Ctrl-O or hold down Alt and press F, O. TextPad, like most applications, also shows these combinations in its menus by underlining the functioning letters. Look at the menu labels at the top of your work window. If each does not have a letter underlined, press the Alt key and one letter will be underlined for each label -- such as the F in File and the E in Edit. Pressing Alt and the underlined letter opens the menu, where each listing also has a letter underlined; in File, for example, O is underlined for Open. That tells you what keys you need to press to launch the box to find and open a file. The underlining confirms that Alt-M, R could have been used to start and stop recording a macro instead of Ctrl-Shift-R.

When you want to create a macro in TextPad, finding these keystroke shortcuts may enable you to get more done automatically than you ever imagined. Good luck!