OS/2 Batch Files To Go
Chapter 2

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.

Creating A Subdirectory And Modifying Your Path

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.

Using A Command Line

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.

Using An Icon

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.

More On Icons

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:

  1. Distinctive. If all your icons look the same, then you lose the main feature of a graphical user interface since you can't quickly identify the function of each icon. To see this problem in action, start up Windows and look at the main screen. Every folder looks the same. That forces you to either try and remember the location of specific folders or to read the titles below the folders. OS/2 folders initially have this same problem but since you can alter the appearance of you folders under OS/2, you can eliminate this problem.
  2. Attractive. You don't want ugly icons on your screen, even if they are distinctive. Depending on your screen resolution, you icons are limited to at most 64x64 pixels with each pixel limited to sixteen colors. One of the things you quickly find out is this small size greatly limits your artistic abilities when creating icons.
  3. Simple. Since your icons are limited to 64x64 pixels but most of them are actually 32x32. They are generally shown on the screen very small, you're going to have to keep the artwork simple in order to be able to make it out on the screen.

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:

  1. Load them from a file of existing icons. I'm not very artistically inclined so this is my favorite way. The disk for this book contains an icon file for most of the batch files. It also contains a collection of public domain icons you can look through for your batch files and any programs you want to use under OS/2.
  2. Draw them yourself. if you are artistic, then drawing your own icons can be both fun and rewarding. If you have access to CompuServe or an OS/2 bulletin board systems, you might want to share your icon creations with others.
  3. Modify existing icons. Often times, the easiest way to develop an icon exactly like the one you want is to take an existing icon and modify it. I have an icon of a floppy disk I'm always modifying for other purposes. For the CHECK.CMD batch file icon, I just took it and added a check mark across the disk. With all the icons on the enclosed disk, you have a good many choices of icons to modify.

Icon Editor

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:

  1. Form Size. This shows you the size of the icon. Typically, icons are 32x32. The numbers represent the number of pixels stored in the icon. The first number is the width of the icon in pixels and the second is the height of the icon in pixels. The Icon Editor can also be used to edit bitmapped files and these can be different sizes. When used to create a bitmapped file, the Icon Editor first prompts you for its size.
  2. Pen Location. This is the current location of the "pen" used to edit the icon. As with Form Size, the first number represents the width coordinate and the second represents the height coordinate. The bottom left corner is 0,0; the top left corner is 0,31 (the numbers go 0-31 not 1-32); the top right is 31,31; and the bottom right is 31,0.
  3. Pen Size. Normally, the pen alters a single pixel at a time, thus the 1x1. Using the Option menu, you can change the pen size to a 2x2, 3x3 and so on up to 9x9.
  4. Hotspot. The hotspot is the portion of the icon that the mouse pointer must be touching when you double click.
  5. Figure type. The Icon Editor can edit icons, pointers or bitmapped files. This tells you what type of file is being edited.
  6. Form name. Once an icon has been saved and has a name, it shows here.
  7. Independent Color Form (=VGA). This line shows the format being used to store the icons. All icons on the disk are stored in "Independent Color Form (=VGA)" format at 32x32 pixels. Other available formats include:

The File menu has four options that are particularly useful for editing batch file icons. They are:

  1. New. This lets you start a new icon with a clean slate.
  2. Open. This lets you open an existing icon and move it into the editor for manipulation.
  3. Save. This is used to save your work to a disk file. If you are saving a new icon file for the first time, the Icon Editor will prompt you for the name to use.
  4. Save as... This lets you save an already saved file to another name. It's useful when you want to modify an existing icon. You load the existing icon using the "Open" option and then save it to a new name using the "Save as..." option. It's best to save the icon to the new name before you begin modifications so you do not forget and save the modified icon back to the original name and overwrite that icon.

The Edit menu has seven options that are particularly useful for editing batch file icons. They are:

  1. Undo. This reverses the last changes that were made.
  2. Cut. This removes the selected portion of the icon (or the entire icon) from the file and places it in the paste buffer. The removed portion of the icon is replaced with a screen colored background.
  3. Copy. This copies the selected portion of the icon (or the entire icon) to the paste buffer without disturbing the icon.
  4. Paste. This copies the icon or portion of icon in the paste buffer to the icon you are working on. Icons or icon fragments loaded into the paste buffer remain there until it's replaced by new material or until the Icon Editor is removed from memory. Icon Editor has it's own paste buffer that it does not share with other programs so using Cut, Copy and Paste in other programs does not affect the Icon Editor.
  5. Clear. This erases the selected area and replaces it with a screen colored background.
  6. Select. Selecting this menu option converts the mouse cursor from a pen to a selection tool. You use this tool to select an area to Cut or Copy to the paste buffer.
  7. Select all. This quickly selects the entire icon. You generally use this to Copy the entire icon to the paste buffer.

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.

Installing An Icon

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.

Have A Disk File Ready

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.

Create A New 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.

Paste An Existing Icon

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.

Drop-And-Drag An Icon

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.

Summary

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