OS/2 offers you two different ways to start your batch files. In this chapter, I'll show you both ways using the SAMPLE.CMD batch file created in Chapter 1 as an example. If you did not create SAMPLE.CMD while reading Chapter 1, you will find a copy of it on the disk included with this book. Just to refresh your memory, SAMPLE.CMD is shown below:
@ECHO OFF ECHO This Is A Simple OS/2 Batch File Example ECHO The Name Of This File Is SAMPLE.CMD ECHO We'll Use SAMPLE.CMD To Illustrate ECHO Using Enhanced Editor PAUSE
The function of these commands will be explained in detail later. Briefly, this batch file will display four lines of information and then wait until you press a key. At that point it will terminate.
SAMPLE.CMD needs to be copied to a subdirectory that is in your path. As a general rule, it's a good idea to collect all your batch files together into a single subdirectory (I use F:\BAT on my system) and to include that subdirectory in your path.
To create a subdirectory to begin storing your batch files in, open the OS/2 System folder and then the Command Prompts folder. Double click on the OS/2 Full Screen icon to get to the OS/2 command line. Move to the root directory with the "CD\" command. Now, create the subdirectory with the "MD BAT" command. You can change to this subdirectory with the "CD\BAT" command. Copy SAMPLE.CMD from its current location with the Copy command. Finally, enter "EXIT" to return to OS/2. Now, you need to add this subdirectory to your path command. Unlike DOS, OS/2 keeps its path command in its CONFIG.SYS file. This is stored in the root directory of the drive containing OS/2. Open this file with either the System Editor or the Enhanced Editor. You will see a line for the path command. Append this new subdirectory by adding a ";C:\BAT" to the end. Of course, you should use the drive and subdirectory appropriate to your system. You should enter the semicolon but not the quotation marks. This change will take effect the next time you start OS/2. You will want to do that before going on to the next session.
The easiest way to run a batch file is to get to an OS/2 command prompt and just enter name of the batch file on the command line. If the subdirectory containing the batch file is in your path, you can run the batch file from any location on your hard disk. Figure 2-1 shows SAMPLE.CMD running in an OS/2 window.
OS/2 is a graphical user interface and it naturally seems backwards to go to a command line to run a batch file. Fortunately, OS/2 makes it easy for you to install a batch file as an icon either on your desktop or in a folder. That way, all you have to do is double click on the icon to run the batch file. The steps for installing SAMPLE.CMD as a desktop icon are described below.
The first step is to open the Template folder. OS/2 uses templates to install new items. Figure 2-2 below shows a desktop with the Template folder open. As is the case with all these screen shots, your screen may look different depending on how you installed OS/2.
Next, move the mouse cursor over the Program icon and press and hold down the right mouse button. Drag the icon off out of the folder and onto the desktop. With templates, this creates a new copy at the location you drag it to. To position the batch file icon inside a folder, open that folder first and drag the Program icon to that folder. As soon as you release the right mouse button, OS/2 brings up the first page of a dialog box you fill out on every new program and batch file. On this Program page, you enter the path to the batch file and the name of the batch file. Optionally, you can enter parameters to pass to the batch file and the subdirectory the batch file should start working in. Figure 2-3 shows this.
The next page is the Sessions page, as shown in Figure 2-4. Here you tell OS/2 what type of session to run and how to handle the window when the program terminates. Notice that some of the options are grayed out in Figure 2-4. Since OS/2 knows from the extension that SAMPLE.CMD is a OS/2 batch file, it does not give you the option of running it in a DOS or Windows window. The next page is the Association page (Figure 2-5) and this is used to link data files to programs. This page is generally not used for batch files.
The next page is the Window page, shown in Figure 2-6. This window is used to control the behavior of the OS/2 window while the program is running. It too is generally not used for batch files. The final page is the General page, shown in Figure 2-7. This page is used to enter a title for the icon and optionally redesign the icon to appear any way you want it to look.
Once you have filled in the necessary information, you can close this dialog box and the batch file icon is ready to use. Figure 2-8 shows an OS/2 desktop with an icon to run SAMPLE.CMD in the middle of it. To run the batch file, all you do is double click on its icon. From that point on, it runs just like it would if you had run it from an OS/2 command line.
Since OS/2 is a graphical user interface, each program and batch file that you wish to run by double clicking on it from the desktop needs an icon. Icons need to have three characteristics. These are:
While these three seem very limiting at first, you will quickly find that it is still possible to create some very artistic icons for your batch files.
There are three different ways to develop icons for your batch files. These are:
To draw your own icons or modify existing icons, you need to use the OS/2 Icon Editor so let's take a moment to explore this program. This is not a complete tutorial on the Icon Editor but it will tell you enough to work with batch file icons. For more detailed information, consult your OS/2 on-line documentation.
There are three ways to start the Icon Editor. The first is to double click on the program. It's stored in the Productivity folder. The other two first require you to select the Settings menu, select the General page and then click on either "Edit" or"Create another" beside the picture of the existing icon. Except that the "Edit" button loads the existing icon into the Icon Editor, all three methods take you to the same screen.
You might want to start the Icon Editor now to follow along in this tutorial. Once you start the Icon Editor, your screen will look like the screen in Figure 2-9.
Along the top of the Icon Editor, you see the main menu. Below that, you see several pieces of information:
The File menu has four options that are particularly useful for editing batch file icons. They are:
The Edit menu has seven options that are particularly useful for editing batch file icons. They are:
Under the Tool menu, you will find an "Color fill" option. This replaces the pen cursor with a tiny paint can. Everywhere you click the cursor, the pixel you click on and every other pixel of the same color connected to that pixel is changed to the currently selected color. This is a quick way to fill the interior of items in your icons.
Now that we have finished our tour of the Icon Editor screen and it's more important menu items, let's see how to draw an icon. The Icon Editor lets you work with a palette of sixteen colors. You will see these to the right of the work area. Additionally, you will see a color labeled "Screen" and "Inverse". The screen color always displays as the same color as the OS/2 desktop screen and makes your icons look professional by giving them a "clear" background. The inverse color is the color that contrasts best with the desktop color.
The Icon Editor allows two colors to be active at once. Move your mouse cursor to one color and press the left button. That is the color that will be painted while you hold down the left button. Now, move the pointer to another color and press the right button. That is the color that will be painted while you hold down the right button. Normally, I set the left button up the be the color I'm working with at the time and the right button to be the background color for the area I'm working in. That way, if I click in the wrong spot using the left button, I can quickly erase my mistake by clicking in the same spot with the right button.
Now we are ready to edit. The best way to think of an icon is a matrix with 32x32 dots. All we are going to do is change the colors of some of the dots in this matrix. We can do this by moving the mouse cursor to a particular pixel and clicking either mouse button or by holding down either mouse button and dragging the mouse cursor across the screen.
By way of an example, let's draw an icon of a 5.25 inch floppy disk. A 5.25 inch floppy disk is mostly a black square with holes in it so let's begin by drawing a black square. You'll see this in Figure 2-10. There are two notches at the front of the disk (one pixel each) and one larger notch (four pixels) on one side of the disk. You'll see these added in Figure 2-11. There is a large hole in the middle for the disk hub, a smaller hole near the front of the disk where the disk is read and a tiny hole (one pixel) near the large center hole. You'll see these added in Figure 2-12. Finally, the hole in the front is entirely filled with the gray center platter of the disk and some of that platter is visible in the large hole in the center. You will see these added in the final version of the icon in Figure 2-13. Save the icon to a disk file and you are ready to use it.
When you go to install an icon for a batch file, OS/2 gives you four different ways to create/install it. You can have a disk file ready, create a new icon from the General page of the Settings notebook, paste an existing icon from the paste buffer in the General page of the Settings notebook or drop-and-drag. Let's look at each of these in more detail.
An icon file is a file created with the Icon Editor that contains one icon and has an .ICO extension. If an icon file exists in the same subdirectory as a batch file or program and has the same name, when you use a template to install that batch file or program to the desktop or to a folder, then OS/2 will automatically use that icon for the batch file or program.
For example, assume you have a batch file called SAMPLE.CMD in your C:\BAT subdirectory that you are planning to add to your batch file folder. Just use the Icon Editor first to create SAMPLE.ICO and save it to your C:\BAT subdirectory. Now, when you install SAMPLE.CMD, OS/2 will automatically use SAMPLE.ICO as its icon.
If you do not have a previously created icon, you can click on the "Create another" button on the "General" page of the Settings notebook. This will take you to the Icon Editor and automatically have you working on the icon for the batch file or program you are installing. If you just want to modify the default folder icon used for folders or the box icon used for programs, just click on the "Edit" button rather than on the "Create another" button.
If you have previously used the Icon Editor and have copied an existing or modified icon to the paste buffer, you can use that icon to replace the default icon for a batch file or program. Just click on the "Create another" button (the "Edit" button will not work for this) on the "General" page of the Settings notebook to go to the Icon Editor. Now, select "Paste" from the Edit menu to paste the icon in the paste buffer into the Icon Editor.
If another item on your desktop using the same icon you wish to assign to an item, then making that assignment is as easy as dragging the icon and dropping it in place. First, bring up the Settings Notebook for the item that is to have its icon changed and change to the General page. Now, click on the item that has the icon you wish to use, using the right mouse button. Hold down the right mouse button and drag the item to the General page and release the mouse button. The new icon will be dropped into place.
This chapter has showed you to different ways to run OS/2 batch files, from the command line and as an icon. It also showed you how to store your batch files in a common subdirectory and include that subdirectory in your path statement so the batch files will run from any subdirectory.
© 2002 by Ronny Richardson, All Rights Reserved