GhostScript for Mac OS X
By Damien Gallop
October 12th, 2002
By now, many of you hard-core unix fans have discovered Mac OS X and its unix roots. Others of you know about them, but don't know where to start. The GhostScript and GhostView applications for viewing PostScript files are a good place.
One of the beauties of unix is its ability to run an ever-growing suite of applications called X Window applications. Most unix machines are X-enabled. Mac OS X is also capable of running these applications, right alongside its already impressive suite of Mac applications. You get two for the price of one. And you get state-of-the-art unix security at no extra cost too.
Key to running these so-called X applications is something called an X Window server, a piece of software that runs quietly in the background on your machine. Its purpose is to support the graphical output of your X applications. Roughly, it is to X as Aqua is to your native OS X applications. The X Window server builds the windows and supports any other display considerations. For more information on the server software and detailed instructions on how to install it on your OS X machine, I invite you to browse through X on Mac OS X - Another Step Forward. If you are running Mac OS X Jaguar by now, you'll also want to click into some fixes, listed in Mac OS X Jaguar Tweaks Part 1 and Part 2 respectively.
For this and most similar installations, you'll need to have installed the Developer Tools CD that came with Mac OS X. If you lost it, you can also register with Apple Developer and download the tools for free. If you are running OS X version 10.2, a.k.a. Jaguar, you'll also want to apply a patch available from osxgnu. The patch fixes a "major bug found in the GNU Autoconf implementation on 10.2 Jaguar."
Assuming you have an X Window server already running on your Mac, let's install. GhostScript is something like an interpreter for the PostScript language. The companion GhostView is something like a viewer plugin for GhostScript. If all you want to do is be able to view PostScript files, then you need both. The key site is the GhostScript homepage. In fact, let's just list the resources right up front:
X11 GhostScript Home
X11 GNU GhostScript Source Code
X11 GhostScript Fonts
X11 GhostScript OS X Package
X11 GhostView OS X Package
X11 GhostView Source Code
X11 GhostScript Manual
X11 JPEG Source Support Files
X11 PNG Library Source Support Files
X11 Zlib Source Support Files
X11 Xaw3D Viewer Support Files
The top entries are all X Window (a.k.a. X11) applications, components, or documentation. MacGSView, on the other hand, is a bona fide OS X Carbon application, which is self-contained and has a version of GhostScript rolled into it. Except for the odd fact that this program never got past beta and therefore is no longer supported, it's a pretty handy tool for viewing PostScript files quickly. If all you need to do is view one single PostScript file right now, then MacGSView is for you. Read no further.
If indeed you are looking to install GhostView for the X Window environment on Mac OS X, then you have two options. You can download and install pre-built packages, all ready for OS X; or you can build the stuff yourself. The pre-built packages are far simpler, but may not be the absolute latest code. On the other hand, it will be pretty recent, and plenty good enough, as this program has been stable for a long time. You'll need two packages, one each for GhostScript and GhostView, both built for you by osxgnu with love. Simply download, unpack, and install each one. Your usual admin-level password will be required. Skip down to the test section now.
The more rigorous approach in several respects is to build the source code yourself. Feel free to browse the online manuals for GhostScript before getting overly involved. Then download the latest stable source code for each of GhostScript and GhostView to your desktop. At press time, the file names are ghostscript-7.05.tar.gz and gv-3.5.8.tar.gz respectively. Expander or OpenUp (Jaguar) should expand these archives for you automatically.
If you're feelin' l-l-lucky, there is extensive information available about fonts. In a recent installation of GS in my office that gave us a font error, all we had to do was drag the downloaded and unpacked fonts folder and drop the thing into the GS share folder like so: /usr/local/share/ghostscript/fonts. However, discovering that pithy bit of information was a little troublesome at the time. You will only need it if for some reason GhostScript fonts fail to install.
Installing GhostScript involves placing various support packages alongside the GS source code. First of all, if it isn't already, open the ghostscript-7.05 (or whatever) folder. You should see about a dozen items, one of which is a file called configure. Good.
Next, find the following three unpacked and opened supporting folders amid the wreckage left on your desktop. Rename them from jpeg-6b, libpng-1.0.2, and zlib-1.1.3 to jpeg, libpng, and zlib respectively. Your mileage may vary, but not by much. Now drag all three renamed folders into your GS folder (where that configure file is).
There is one last thing, a standard X11 header library called Xaw3D, which was downloaded above and got unpacked as folder xc. Drill down into it and drag the Xaw3D folder into /usr/X11R6/lib/X11. Strictly speaking, only the name.h files are required for this, but we want to keep the procedure as simple as possible. If /usr is invisible (this is one good reason to have TinkerTool on your system), then use the Go to Folder feature of Finder's Go menu to get there. Xaw3D provides a standard set of software tools for building window widgets such as sliders.
Open a Terminal window. If you are new to Terminal and the unix command prompt generally, you might like to browse The Mac OS X Shell for a quick orientation.
Type cd (leave a space) at the Terminal prompt. Now click, hold for a moment, and drag the miniature folder icon from the title bar of the opened ghostscript-7.05 (see above comment) folder onto your Terminal window. Click back to it and press Enter. You're in. Type ls to get a directory listing. About a dozen items plus the three additional folders should be listed.
Type the following commands to configure, build, and install GhostScript:
% sudo make install
Each step will take a while with copious informational messages, but nevertheless should fly without a hitch. The binaries should get installed into /usr/local/bin and /usr/local/share/ghostscript/7.05. A fonts folder should be in the latter place also. If not, rename the one you downloaded above, and move it there.
While you could download and install the GhostView and supporting Xaw3D source file archives manually, it's just easier to use the pre-packaged GhostView package from osxgnu. I had it installed in less time than it took to download, which in turn took less time than digging through my by now imposing layers of desktop windows. Again, the archive should unpack automatically. If not, hand the job to OpenUp or Aladdin Expander. Double-click the ghostview-3.5.8.pkg file, give it your admin password, and Bob's your uncle.
An additional reason why I suggest using the pre-built version here is that I discovered a mistake in one of the GhostView readme files. Fixing that one mistake got me to the next step, but I was stymied at that point. For completeness, though, we'll review the steps.
Open the root GhostView source code folder, named something like gv-3.5.8. Set your Terminal to it in the same way you did with GhostScript's source folder. For the record, type cd (leave a space) at the prompt. Now click, hold, and drag the miniature folder icon from the title bar of the opened gv-3.5.8 folder onto your Terminal window. Click back and press Enter. You're there. Now create a couple of logical pointers called links (a.k.a. shortcuts) with the following commands (after the sample cd):
% cd /Users/damien/Desktop/OpenUp/gv-3_5_8_0/gv-3.5.8
% ln -s /usr/X11R6/lib/X11 X1
% ln -s /usr/X11R6/lib/X11/Xaw3d Xaw3d
When GhostView starts the build process, it will now be able to find the Xaw3d header files. Continue on with the actual build, using the following commands, lifted from INSTALL.unix and slightly modified:
% make Makefiles
% sudo make install
% sudo make install.man
% sudo make install.doc
However, as noted above, my build stopped during the make step. You might get luckier. I just got lazy and used the pre-built package instead. Finally, type exit to end your Terminal session.
Open a fresh Terminal window. The simplest test is to issue the command gs -v and see what happens. If you get an older version, then OS X is seeing an older copy. If you get Command not found, then something broke during the installation. Scroll back up in your Terminal window and look for fatal errors among the informational messages (hint: search for "error"), particularly as the last couple of steps during any of the three commands. If it looks hopeless, drop me a line.
To delete an older version of GhostScript, issue the following commands in your Terminal window:
% cd /usr/bin
% ls gs
% sudo mv gs gs.old
Now retest. Does it return the correct version this time? If you get Command not found, then something broke. As noted above, scroll back in your Terminal window and look for fatal errors. If everything is okay, then you can remove the old version altogether with a sudo rm gs.old.
All okay so far? It's time to start GhostView itself. You need your X Window server running now. Assuming it is, open a fresh Terminal window and type gv. The application should start. For a sampler PostScript file, press Open and dig down through your GhostScript source folder, which should still be in your OpenUp or Desktop folder. A couple of layers down is an examples folder, with lots of good stuff. The file tiger.ps is a good test.
One of these days I will do a separate treatment of the OroborOSX X Window manager for Mac OS X. To my mind, it is very nearly perfect. In my office, the KDE desktop on Linux rules. There is a lot to like about it too, but I prefer OroborOSX, and would import just one feature from KDE: push to back. (Just a plug, there, Adrian, for the next version, in case you're tuned in! :-)
Every X Window machine requires a window manager. The actual X Window server is exactly that, a server. You never see it. Typically it gets installed with some default window manager, the add-in, if you will, that provides the actual windows, title bars, scrolling, and so on. If you wisely chose the OroborOSX window manager for your system, then you have the ability to add GhostView into a drop-down menu of favorite X applications. Of course, other window managers have their tricks too.
Start OroborOSX and click the Launch menu. Select Edit Launch Menu Items. A Finder window with a collection of Launch icons will appear. Copy (Option-Drag) one of them, Xeyes, say, and rename it GhostView. Now open the latter in TextEdit. Note that only the middle few lines get modified at all. Here are the changes:
set argums="-geometry 700x500+100+50"
Save your work. Now bring OroborOSX back to the front, and pull down Launch, Rebuild Launch Menu. GhostView will be at the bottom. Test it out!
To use GhostView in a convenient way, place (download) PostScript files onto your desktop. Then it's simple to open them. I have OroborOSX in my Login Items system preference, so that my X Window server starts automatically. Since I'm logged into OS X continually (at home, anyway), X is always available to me.
If your PostScript page is larger than your window, a CAD drawing, say, then try out the pan button, innocuously located between Save All and Redisplay. It's neat! It's also far more convenient than scroll bars. If you prefer, there is a scale button, fourth to the right of File. GhostView also has a clever way of handling multiple pages in a document.
GhostView can handle PDF files as well as PostScript. For most PDF situations you'll likely prefer Acrobat Reader. But it's always good to have additional ways to do things. In particular, GhostView gives you a way to read PDF documents within the X environment. On a Mac, that isn't much of an issue. But on a standard unix box, GhostView may be the only game in town for PS and PDF files.
In retrospect, I suppose I wouldn't recommend GhostView for your first X Window application project after all. To get your feet wet with some simpler X applications, you might take a look at Building An X Application for Mac OS X. Xmahjongg, described therein, is a venerable X application that I guarantee will build for you under OS X, using the same three basic steps that many unix builds use, namely the ones used to build GhostScript above.
That said, GhostScript and GhostView are essential equipment on the well-equipped X machine. It's worth the effort to slog through it once.
On an entirely unrelated note, that Option key will get exercised more with Jaguar. I noted in my last couple of articles Mac OS X Jaguar Tweaks Part 1 and Part 2 that Restart now requires confirmation, and Information windows, raised with Cmd-I, now have the property inherited from Mac OS: one window per object. Readers wrote to me and pointed out that pressing the Option key for both of these operations gets you the pre-Jaguar behavior once again, which respectively are a restart with no questions asked and a single information window that automatically follows your mouse around. I truly appreciate that people took the time and effort to write me about this. Now I'm waiting for someone to come up with the NetInfo (I know it's in there somewhere) property that reverses the behavior for each of these two permanently, thereby eliminating the Option key press altogether. Odds are pretty good that there is other OS X functionality that could benefit by this as well. Do tell if you know.
Finally, I am cutting out of town for a bit. See you in a few weeks. Ciao.