|
Shell macros for MTs
Have you ever been typing along and wished you could have a calculator or an Internet connection available to you at the touch of a button? How about that new drug reference on CD-Rom you just bought? You can start any program with a macro from your favorite word processor, if you know how to access the shell.
The operating system shell
When you want to run a program on your computer you need to tell the operating system (OS) what program you want to run. Then the OS executes that program. There are different ways to do this depending on the OS you use. In DOS one types the name of the program on the command line. In Windows one double-clicks the icon of the program or selects a shortcut to the program from the Start menu. The program you start then runs and you can use it normally. Modern word processing programs have made it possible for you to access the OS while they run. In fact, WP51, WP8, and Word 97 all have macro commands that will execute programs from inside the word processor.
Command line required
There are two things you need to know before you can execute secondary programs from your word processor. The first is the exact command path to the program you want to run. This is the command path to execute WP51 on most systems:
c:\wp51\wp.exe
Typing the above at a DOS command prompt will execute WP51 provided there is a WP51 directory on your C: drive that contains a program named wp.exe.
The easiest way to find out the command path of the executable is to open your Start menu | Programs and right click the item you want to run. This will bring up a pop-up menu. Select Properties and then make sure the Shortcut tab is in front. If it isn't you can select it by clicking on it. Now find where it says Target. That is the target of the shortcut you right-clicked. Look familiar? It's also the path to the program. Either write down all the text in the Target field or highlight with the mouse and press Ctrl + C to copy it to the clipboard.
The above instructions only work in Windows 98. If you are using Windows 95 you will need to open the Start menu and choose settings, then Taskbar & Start menu. Then click on the Start Menu Programs tab to bring it forward. Next click on the Advanced button. This will open up Windows Explorer to the Start Menu directory located inside the Windows directory. Open the Programs folder by clicking on the +. In the right pane you should see a fairly accurate representation of your Start menu. Locate the program you want to run and right-click it to open the pop-up dialog. Choose Properties and find the Target field on the Shortcut page. Write down or copy everything in the Target field.
Using the above instructions I got these paths to execute the Calculator program and Internet Explorer:
C:\WINDOWS\CALC.EXE
"C:\Program Files\Internet Explorer\IEXPLORE.EXE"
The quotes are necessary for the path to Internet Explorer because of the long file names, if the quotes weren't there you'd need to manually truncate all directories longer than 8 characters to 6 characters and add a ~1 at the end. Like this:
C:\Progra~1\Intern~1\IEXPLORE.EXE
Shell macro command
Now that we have the path to run our target executable we need the second ingredient, the appropriate macro command.
In WP51 the Shell command is Ctrl-F1. To record a shell macro in WP51 press Ctrl-F10 and name the macro something like "calc" (without quotes). Enter a description if you like and press Enter. The bottom left corner of your screen should now say Macro Def. Press Ctrl-F1 and then 2. Now the bottom of the screen should say DOS Command. Type "c:\windows\calc.exe" and press Enter. That will start the Calculator. Close the Calculator by pressing the X in the top right corner of its window. Switch back to your WP51 screen by clicking the appropriate button on the Taskbar. The bottom of your WP51 screen should now say "Press any key to continue." Press a key and then press Ctrl-F10 to stop recording the macro. Test the macro by pressing Alt-F10 and typing "calc" (without quotes, of course).
To have our shell macro start Internet Explorer just follow the above instructions but substitute net for calc and "C:\Program Files\Internet Explorer\IEXPLORE.EXE" (quotes are necessary this time) for c:\windows\calc.exe.
(NOTE: The above macros assume that you are using WP51 from inside Windows 95/98. If you are using WP51 in MS-Dos mode without Windows running you will get an error when you try to start any Windows-based program.)
A shell macro for Word 97
You can accomplish the exact same thing in Word 97 but you have to do a little Visual Basic programming. Just a little, I promise. (Still it's always a good idea make a backup of your Normal.dot file before you do anything with macros in Word.)
Start Word 97. Open the Tools menu then Macros > Macros... or press Alt-F8. Type "calc" (without quotes) under where it says Macro Name then press the Create button to the right. This will activate the Visual Basic editor and you should see something like:
Sub calc()
'
' calc Macro
' Macro created 12/02/99 by Mike DeTuri
'
End Sub
Your cursor should be blinking right above the End Sub line. At this point you are directly editing macros in your Normal.dot file so if you don't want to mess anything up, only make changes above the End Sub line and below the Sub calc() line. (If you do accidentally edit something else and you aren't sure how to get it back to its original state Exit out of the Visual Basic editor and don't save your changes. This is also where that Normal.dot backup would come in handy.)
All we need to do this macro is add the following two lines of code right where the cursor is above the End Sub line:
Dim var1
var1 = Shell("c:\windows\calc.exe", 1)
So now the completed macro should like this:
Sub calc()
'
' calc Macro
' Macro created 12/02/99 by Mike DeTuri
'
Dim var1
var1 = Shell("c:\windows\calc.exe", 1)
End Sub
Save the changes to Normal.dot by pressing Alt+Q.
You can change this macro to execute whatever program you like just by changing the path in quotes. To have this macro run Internet Explorer just replace "c:\windows\calc.exe" with "C:\Program Files\Internet Explorer\IEXPLORE.EXE".
Test the macro by pressing Alt-F8 and typing "calc" and pressing Enter or clicking on the Run button.
A shell macro for WordPerfect 8
We can also create a shell macro for WP8. Here we will only need to add one line of code to the macro to get it to do what we want. Very simple.
Start WP8. Open the Tools menu and choose Macro > Record... or press Ctrl-F10. Name the macro calc.wcm by typing "calc" in the File Name field, without quotes, and pressing Enter. Now you are recording your macro. Type "this is a test" and press Ctrl-F10 again to stop recording.
To edit the macro we just created open the Tools menu and choose Macro > Edit. Type "calc" in the File Name field and press Enter. Your calc macro should look like this:
Application (WordPerfect; "WordPerfect"; Default!; "EN")
Type (Text: "this is a test")
Replace line 2 of the macro so that your macro looks like this:
Application (WordPerfect; "WordPerfect"; Default!; "EN")
AppExecute("c:\windows\calc.exe")
Press the Save and Compile button to save your changes. Exit the macro as you would any other WP8 file.
You can change this macro to execute whatever program you like just by changing the path in quotes. To have this macro run Internet Explorer just replace "c:\windows\calc.exe" with "C:\Program Files\Internet Explorer\IEXPLORE.EXE".
Test the macro by pressing Alt-F10, type "calc", and press Enter.
Copyright 1999 by Mike DeTuri (reprinted from Computer Solutions Vol. 1, Issue 5)
|