Printing Documents from HyperCard IIGS

Printing Documents from HyperCard IIGS (ABC95.12)

by Gareth Jones


Remote Printing From Hypercard

HyperCard IIGS has two commands for communicating with other applications: "open [document] with [application]" and "print [document] with [application]." The only catch is that the application must have been written to receive these messages. In many cases, such commands do no more than launch the application. With a properly written application, however, all you need is a short script to add remote-control display or printing of files to your list of HyperCard tricks.

Creating The Button

To create a simple, workable, document-printing button in HyperCard IIGS, follow these steps:

  1. Create a new button by choosing "New Button" from the "Objects" menu.
  2. Drag it into place. Anywhere will do.
  3. Double-click it.
  4. Click on the "Script" button
  5. Type in this script:
on mouseUp
 answer file "Select a text file to print:" of type 80
 if it is "Cancel" then
 exit mouseUp
 else
  put it into wpFileName
  print wpFileName with ":HardDriveVolume:FolderName:AppleWorks.GS"
 end if
end mouseUp

Locating The Application

You will have to replace the pathname in line 4 of the script with the pathname of the program that you intend to print the document with. You've got three methods for telling HyperCard IIGS the location of the application you want to print with.

1. You can spell out the entire pathname in the script. E.g.

print ":MyDisk1:TextFileFolder:MyTextFile" with ":MyDisk2:My.Word.v1.4:My.Word"

(Brutally simple, but it works).

2. You can specify the Volumes and folders in the "Search paths" page of the HyperCard IIGS Home stack. (This isn't the place to discuss this in detail).

3. You can just put in the filename of the Application, and let HyperCard IIGS put up a Standard File dialogue box that asks you to locate it. (This could get tiresome).

On the whole, I prefer the second method.

Specifying The Filetype

You may also have to modify the number at the end of line 2 to match the filetype of the document(s) that you wish to print. There are a number of points to make about the filetypes specified in the script. First of all, filetypes are usually given as hexadecimal (base 16) numbers, as is indicated by a dollar sign in front of the number. HyperCard IIGS, however, requires that they be listed as decimal numbers (base 10).

The Calculator desk accessory that comes with System 6 makes it easy to convert between the two types of numbers. Simply select "Calculator" from the Apple menu and click on its zoom box. Click on the "hex" button that shows up on the expanded calculator, then enter the hexadecimal number of the filetype you are interested in. In my case AppleWorks GS Word Processing files have a filetype of $50, so I enter "50." The next step is to press the "Dec" button, and the "50" in the calculator's display suddenly turns into its decimal equivalent, "80." This is the number that should be used in line 2 of the HyperCard script.

Line 2 of the script produces a file selection dialogue box that ideally would show just files of the correct kind. Unfortunately, different file formats often have the same filetype. Where AppleWorks GS Word Processing files are Type $50, Aux Type $8010, Teach files are Type $50, Aux Type $5445, and certain other word processing documents differ only in their Aux Types. The syntax of the "Answer file" command does not allow you to identify files by Aux Type, so this is a limitation that we have to live with (until someone writes a more capable version of "Answer file" as an XCMD). Fortunately, selecting a file of the wrong format does no harm you are simply informed that it will not print.

Here is a list of filetypes and aux filetypes that may be useful in your experiments. All filetypes are given in decimal form.
type 4text
type 26AppleWorks Word Processing file
type 79AppleWorks GS Database
type 80AppleWorks GS Word Processing file
type 81AppleWorks GS Spreadsheet
type 83AppleWorks GS Drawing
type 84AppleWorks GS Page Layout.
type 85HyperMedia document (e.g. HyperStudio or HyperCard stack)
type 192GS painting (filetype $C0)

Using Specific Applications

As mentioned, not all applications were written to support remote opening and printing of files. As a general guide, if you can print a document from the Finder by selecting a document icon then selecting "Print..." from the File menu, you can Open or Print it with HyperCard IIGS commands as well. This section gives you a head start on the experimentation by listing my successes, and a few failures.

AppleWorks GS will open or print documents that are in its own file formats. AppleWorks GS draws a distinction between its own file formats, which are accessed through the "Open..." command, and AppleWorks, text, and Apple Preferred Format paint documents which are accessed through the "Import..." command. It will open or print the former formats under command from HCGS, but not the latter.

There are many disappointments in the search for applications that will open and print Teach documents. You can't issue open or print commands to the handy desk accessory word processor called ShadowWrite (or Hermes) because, as HCGS will inform you, it is a desk accessory, not an application. WordWorks Pro (from SoftDisk GS) will not even open a file on command. Teach will open the documents on command, but will not print them. However, Gary Little's program "My Word!" opens and prints Teach, AppleWorks, AppleWorks GS, and text documents. If you have and like another TextEdit-based word processor, experiment to see what it will do.

Printing graphics could be a problem, as neither Platinum Paint nor DreamGrafix will Open or Print documents from HyperCard commands. On the other hand, SuperConvert, from Seven Hills Software, will Open or Print many kinds of graphic on command.

Here's a hot tip! Have you ever wished that HyperStudio had HyperTalk, or HyperCard had some of the unique features of HyperStudio? It is possible to use those programs together in a single project since HyperStudio will obey HyperCard's command to open a stack, and then returns you to HyperCard when it quits.

SUMMARY

The ability to display a file or print it under the control of a HyperCard script has some intriguing possibilities. For example, you could use it to display 320-mode or 3200-colour pictures that HyperCard cannot, itself, display. Another possibility is to save a text file to disk and then print it with My Word!, which has better ability to control the font and margins of the printout. In addition, the potential of linking HyperCard and HyperStudio stacks with the "open" command is exciting and unexplored. These commands certainly should be in the back of your mind as you develop your HyperCard projects.

Gareth Jones is the former Editor of Apples B.C. News and a Contributing Editor of Hyper Quarterly, a new magazine-on-disk devoted to HyperCard IIGS stacks.


HyperCard IIGS Article Index | HyperCard FAQ | Hyper Quarterly Home