Archive for the 'Mac OS X' Category

Report-an-Apple-bug Friday! 18

Friday, April 7th, 2006

This bug is Preview uses its own made-up value for resolution of PostScript images. It was filed on 2006-04-07 at 00:45 PDT.

I discovered this bug when making the navigation buttons I donated to Simone Manganelli (you may recognize his1 name if you’ve been reading the comments on this blog) for switching among his stylesheets. The PNG images that I saved from Preview showed up as 32×32 in the Finder. So I had to open the EPS file in Photoshop, which is how I found out that the resolution was wrong.


Summary:

PostScript documents can specify a resolution. Preview, when converting to PDF and then to raster format, ignores that value and uses 150 dpi instead.

Steps to Reproduce:

  1. Open an Encapsulated PostScript (.eps) file containing an explicit resolution in Preview.
  2. Save as PNG or TIFF.
  3. Open the PNG or TIFF in Photoshop. (NOTE: This is incorrect. I meant to change this but forgot. See below. —PRH)
  4. Choose “Image Size”. (NOTE: This is incorrect. I meant to change this but forgot. See below. —PRH)

Expected Results:

The resolution is as stated in the EPS file.

Actual Results:

The resolution is 150 dpi in a TIFF file, or 150.0124 dpi in a PNG.

Regression:

None known.

Notes:

The Document Structuring Conventions, upon which EPS is based, provide for a resolution in the optional “Requirements” comment. For example:

%%Requirements: resolution(x,y)

Preview appears to target a specific length in real-world measurements (inches or cm). Not only does it force the resolution to 150 dpi, it also rasterizes the image at double-size (which compensates for the resolution change, but only in applications that pay attention to the DPI — which are not many, at least in the case of PNG files). This is symptomatic of Preview converting to PDF as an intermediary, as proven by using pstopdf and then saving the PDF as PNG or TIFF — it is still saved as 150 dpi, double-size.

The solution is twofold:

  1. Rasterize at 72 dpi by default. This is the default resolution of PostScript, upon which PDF is based, so it is sane to expect both PDFs and PostScript (including EPS) files to be rasterized at that resolution by default. If you really want the double-size behavior, then the DPI should be saved as 144 dpi instead.
  2. Allow the PS-to-PDF converter to accept a resolution in its PS input.

On 2006-04-07 at 01:48 PDT, I added the following information:

Oops. I meant to change the Steps to Reproduce but forgot. Here are the correct steps:

  1. Open an Encapsulated PostScript (.eps) file containing an explicit resolution in Preview.
  2. Save as PNG or TIFF.
  3. Choose “Get Info” from Preview’s Tools menu, or press ⌘I.

  1. I’m assuming that Simone Manganelli is a he. If not, sorry; no offense intended.

Technorati tags: , , .

Report-an-Apple-bug Friday! 15

Friday, March 24th, 2006

This bug is Terminal leaves files open when invoking shell directly. It was filed on 2006-03-24 at 23:45 PST.

UPDATE 2006-03-25: Uploaded the test app to GeoCities. Linked below.

UPDATE 2006-08-27: By GeoCities, I now mean boredzo.org. Link updated.


Summary:

When Terminal invokes a specific shell directly, rather than by invoking /usr/bin/login, several files are left open.

Steps to Reproduce:

  1. Launch Terminal.
  2. Terminal menu→Preferences….
  3. Select “Execute this command (specify complete path):”
  4. Specify the complete path.
  5. File menu→New Shell.
  6. Run the attached test app, or run ps and then run lsof with the pid of the shell.

Expected Results:

The test app prints “3”. lsof reports only three file descriptors: 0, 1, and 2, the respective FDs of stdin, stdout, and stderr.

Actual Results:

The test app prints “10”, “11”, “14”, or some other number. lsof reports a lot of open files having to do with Carbon (suggesting that the shell probably did not open them itself).

Regression:

None known.

Notes:

The test program creates and opens a file, and reports the FD it gets back from open. open returns the first FD that was available. In the absence of any other open files, this should be 3 (because that’s the FD after stdin, stdout, and stderr).

When I tested using test-app-free version of the above steps, I did observe that zsh 4.3.1 leaves open one file of its own (the terminal device). Perhaps it opens /dev/tty. This open file is not passed onto subprocesses, however, as is demonstrated by the test app.

Terminal (or Carbon) is responsible for all the other files that Terminal leaves open; this is obvious from the paths of the open files. Maybe login is closing them; in this case, Terminal should do this itself when the user chooses to bypass login.


Technorati tags: , .

Report-an-Apple-bug Friday! 9

Friday, March 17th, 2006

This bug is Terminal should support xterm‘s 256-color mode. It was filed on 2006-03-17 at 20:44.


Summary:

xterm has a 256-color mode. Terminal should support it.

Steps to Reproduce:

  1. Launch Terminal.
  2. Run 256colors2.pl from the above website.

Expected Results:

Lots of pretty colors.

Actual Results:

Lots of backslashes and 16 pretty colors.

Regression:

None known.

Notes:

Some applications, including vim, look for TERM to be set to xterm-256color. Therefore, Terminal’s default should be changed to this if 256-color support is added.


Technorati tags: , .

How to eject a CD

Friday, March 17th, 2006

I posted this to IOMUG‘s mailing list on 2004-04-05. I’ve HTMLized it, added Unicode, and added Tiger info.


Here are all the ways to do it using Apple software (the OS and the programs that come with it). Note that all the same methods work for DVDs as well, so, if you have a DVD drive, you can read “CD/DVD” wherever you see “CD”. Unless otherwise noted, these all take place in Finder.

These require a CD in the drive.

  • Hold down the mouse button at startup.
  • Select the volume and press ⌘E, or choose Eject from the File or Special menu.
  • Drag the volume to the Trash (on Mac OS X, the Trash icon will change to an ⏏ icon).
  • Mac OS only: Select the volume and press ⌘Y, or choose Put Away from the File menu. This is the only way to unmount a server in Mac OS.
  • Mac OS 7.5 and later only: In the Control Strip, choose Eject from the Audio CD module (the one with a CD icon).
  • Mac OS 8 and later only: Right-click on the volume and click Eject.
  • Mac OS X only: Select the volume and click the ⏏/Eject button on the toolbar.
  • Panther only: Select the volume and click the ⏏ button in the sidebar. (Works in Navigation Services dialogs, too.)
  • Mac OS X only: From Disk Utility, select the volume and click the ⏏/Eject button on the toolbar.
  • Mac OS X only: From Disk Utility, select the volume and choose “Eject” from the File menu.
  • Mac OS X only: Press the Eject key on the keyboard. (Thanks, Andrew Wellington! Added 2006-03-18.)
  • Old Mac OS X only: From Terminal, type “disktool -e device”. (Thanks to Sören Nils “chucker” Kuklau for telling me about this one.)
  • Mac OS X only: From Terminal, type “diskutil eject device”. device is one of /dev/diskN”, “diskN”, or “/Volumes/Name”. Use diskutil list to determine an appropriate value of N. (Thanks to Graham Booker for reminding me of diskutil.)

These do not require a CD in the drive if you have a tray-loading drive. In this case, the tray will open so you can put in a CD.

  • From Open Firmware, type “eject cd”. (Note: you can’t substitute “dvd” here. It must be “eject cd”, even if you have a DVD drive.)
  • Burners only: from Terminal, type “drutil tray eject -drive N”, where N is the number of your drive. You can use “drutil list” to determine the value of N.
  • Burners only: from Terminal, type “drutil eject -drive N”.
  • Press F12, or on *Books, press fn-F12. On Mac OS 9, you may need to add the ⌥ key, depending on your keyboard settings.
  • Mac OS X only: with the Eject MenuExtra enabled, choose “Eject ‘Volume Name’” or “Open/Close CD-ROM Drive” from the ⏏ menu.
  • In iTunes, click ⏏ on the iTunes window.
  • In iTunes, choose “Eject Disc” from the Controls menu.
  • In DVD Player, click ⏏ on the controller.
  • In DVD Player, choose “Eject” from the Controls menu. (May vary by version. What I said is true of 4.0, i.e. Panther’s DVD Player, and 4.6, i.e. Tiger’s DVD Player.)

* Mac OS is the OS before Mac OS X. The latest version of Mac OS is 9.2.2.

** You can enable this MenuExtra by opening /System/Library/CoreServices/Menu Extras/Eject.menu.

Report-an-Apple-bug Friday! 4

Friday, February 24th, 2006

I couldn’t remember on Friday what it was that I wanted to report. I finally remembered the Saturday afternoon after. so once again, I’m posting it late and forging the date. No rhyme intended.

This bug is TIFF files not supported as bundle icons, an enhancement request. As usual, I did not modify it for the open web except to HTMLize.


Summary:

Mac OS X only accepts IconFamily (icns) files as bundle (e.g. application) icons. Mac OS X should also accept TIFF files, which are more flexible and arguably easier to create (depending on your Terminal-fu).

Steps to Reproduce:

  1. Create a bundle.
  2. Place a TIFF file named “Icon.tiff” in the Contents/Resources subdirectory of the bundle.
  3. In Contents/Info.plist, set CFBundleIconFile to either “Icon.tiff” or “Icon”.

Expected Results:

Mac OS X, upon noticing the bundle, recognizes the TIFF file as the bundle’s icon. Finder uses as the bundle’s icon the image from the TIFF whose dimensions most closely match the target icon size defined in View Options.

Actual Results:

The bundle has a generic bundle or application icon.

Regression:

None known.

Notes:

A TIFF file can hold one or more images of any size. TIFF files containing more than one image can be created with the third-party tiffcp utility, or Apple’s tiffutil -cat that is based on tiffcp.

An IconFamily file is limited to five resolutions: 16-pt, 32-pt, 48-pt, 128-pt, and 256-pt. Also, the 256-pt resolution cannot be created with any current software. It is theoretically supported by the operating system, but no current application can create an IconFamily containing a 256-pt image — not even Icon Composer. tiffutil/tiffcp can and will easily add a 256-pt image to a TIFF file, or any other size image.

Besides the obvious MIP-mapping advantages, TIFF also supports compression. Images in a TIFF file can be compressed with JPEG, LZW, or PackBits, among other codecs. IconFamily does not support any compression. So given a TIFF file and an IconFamily file with the same set of images, the TIFF file would likely be smaller with the advantage of compression. This would also help ameliorate the disk-space hit of adding 256-pt images to some bundle icons.

UPDATE 2006-08-27: This was written before I found out that the 256-px images are compressed when they are stored into an IconFamily structure/file, and decompressed upon retrieval.

On the Safari shell script exploit

Wednesday, February 22nd, 2006

reading John Gruber’s account, I had a couple of ideas on what to do about it.

  1. in Finder, when a file has a custom “Open With” assocation on it, badge the file’s icon with the application icon. in this case, it would have the Terminal icon badged onto it.
  2. in Safari, add a new warning when a file contains an “Open With” that points to an application that wouldn’t normally handle that type of file. in this case, Terminal does not normally open JFIF files, and this should cause a warning.

discuss.

Other Apple test utilities

Wednesday, January 25th, 2006

I mentioned that Apple have an Image Units Validation Tool.

I just looked some more, and they also have:

enjoy.

Compression and archive formats: A description

Sunday, January 15th, 2006

Recently, I went to Apple’s games site and downloaded a bunch of puzzle/arcade games. I was dismayed to find that many of these games were distributed in formats other than UDIF (the .dmg format). So clearly this matter bears some explanation.

This is going a two-part post. Part 1 follows. Part 2 covers why you should use a plain dmg (no StuffIt or *zip sprinkles) to distribute your software. This was originally one long post, but I Kill Billed it.

UPDATE 2006-01-15: Changed the initials to capital letters (sentence case), so it reads better; changed to smart quotes. Also added mention of Compact Pro and a link to ESR’s article on The Art of UNIX Programming.

UPDATE 2006-02-17: Linkified Compact Pro.


Part 1: A brief history of compression and archiving

First, a couple definitions:

A compression format contains compressed data: data that has been fit into less space than it would without compression. gzip format is a good example of this; a gzip file is nothing but compressed data. It doesn’t even contain a filename — that’s worked out from the name of the gzip file. (for example, if you download Foo.tar.gz, and rename it Bar.tar.gz, and gunzip it, you will get a file named Bar.tar.)

An archive format aggregates one or more files into a single file. USTAR format (the format used by tar and pax; see below) is a good example of this. It isn’t compressed (unless you compress it with gzip, bzip2, or something else), but it is an archive format.


On Mac OS (that is, before Mac OS X), almost all software was distributed in StuffIt format. StuffIt was software developed by Aladdin Systems (now Allume Systems). (Before StuffIt caught on, the Mac market was majorly ruled by Compact Pro. But StuffIt, combined with apathy from the author, defeated it.)

The StuffIt format was both an archive format and a compression format: a StuffIt file was an archive of files whose contents were compressed. StuffIt achieved its greatest popularity with the advent of the internet — Mac OS applications could not be transmitted over networks, because most of their essential parts were in the resource fork, which was omitted when a file was sent to another operating system or copied to another file system. StuffIt, being data-fork only, kept everything intact. (MacBinary was another archive format, developed separately, that served that purpose, but did not offer compression.)

In the interest of being thorough, I should mention that MacBinary and BinHex were also used on top of StuffIt files (.sit.bin and .sit.hqx, respectively). MacBinarying a StuffIt file accomplished exactly nothing: you were wrapping what was already wrapped. BinHex was useful if the file was believed likely to undergo newline conversion (conversion between CR, which indicated a newline on the Apple II and Mac OS; LF, which indicated a newline on UNIX; and CRLF, which indicated a newline on DOS and Windows), but I think such situations were really the minority.

Eventually, Allume completely replaced the old StuffIt formats (there are at least four versions) with StuffIt X. StuffIt X supported much more detail in how the compression was specified, as well as Unicode filenames, 64-bit dates, packages (folders that behave as files, e.g. .app bundles) and stronger encryption. But it never achieved popular usage, for two reasons.

The first reason was simply that StuffIt 6-8 sucked. The larger reason is that OS X has its own facilities for archiving, compressing, and expanding files.


Mac OS had for many years (I used it on a Mac Plus and an SE/30, among other models) an application called Disk Copy. You’d open Disk Copy, then insert a floppy disk (80mm [aka 3.5″] disks were the prevailing medium of the day). Disk Copy would read from the disk, then prompt you to insert a blank disk or cancel. You could do this as many times as you wanted; thus, Disk Copy was a disk-duplication (i.e. copying) program.

In Disk Copy version 4.2 (I think), Apple added the ability to create disk images. A disk image is literally a snapshot of the contents of a disk. Disk Copy was able to both create and apply these disk images.

The idea was that you could make an image of a disk, make a hundred copies, sell them all, then come back with another box of disks and make a hundred more copies. Resumable duplication, in effect, without having to read the disk in each time. It was also possible to distribute disk images (by compressing them and/or sending them over the internet), so that the image could be applied to floppy disks by separate individuals.

Disk Copy also had the ability to ‘mount’ these images. This was the equivalent of putting the disk in, as it would show up on the desktop, but you could have incinerated the original real disk and it would still work — everything was read from the disk image. Once the internet got popular, it was possible to send a disk image to somebody else, and they could make their own floppy disks from the disk image.

Around the time of System 7.5, Apple began distributing SMIs: Self-Mounting Images. Regular disk images were Disk Copy documents, so when you opened one, Disk Copy would launch to take care of it. An SMI had the disk-mounting code in it, so you didn’t need Disk Copy anymore. I think Disk Copy was made a custom-install option at this point.

Disk Copy 6 introduced a new format called NDIF (New Disk Image Format), which came in several variants: a read/write format, a read-only uncompressed format, and two read-only compressed formats (one using an unknown codec, and the other using a proprietary Apple codec named KenCode).


Independently of all of this, UNIX in all its flavours (and later GNU operating systems as well) had a program called tar. tar is a tape archive program, designed for recording and playing back backup tapes.

At some point, tar gained the ability to make tape-archive files (now colloquially known as tarballs). This is the -f part of tar -cf. Tarballs, in this way, are analogous to disk images. The tar format was eventually standardised as USTAR.

The UNIX philosophy of software design is ‘do one thing well’. So the tar format (and its companion application, in all its various separate implementations) never gained any sort of compression. Instead, various compression programs are used in series upon the tar data. The original way to do this was tar -cf - | compress > foo.tar.Z.

Eventually, gzip replaced compress, and not long after, GNU tar introduced a -z option that made tar do the pipeline into gzip for you. Thus were compression and archiving merged in the UNIX world.


With Mac OS X, Disk Copy came back, and SMIs went away, and a new disk image format was introduced: UDIF. Like StuffIt X, UDIF was created to handle all the new and improved metadata supported by HFS+ — most conspicuously, Unicode filenames — as well as strong (AES-128) encryption. The old disk images had a filename extension of .img; this, unfortunately, was quite a common extension (used by at least one other imager and at least one picture format), so UDIF was given the filename extension of .dmg.

UDIF is a very flexible format. It comes in many variants. As of Mac OS X 10.4.3, these include:

  • Read-only, uncompressed
  • Read/write, uncompressed
  • Read-only, ADC compression (another Apple codec)
  • Read-only, zlib compression
  • Read-only, bzip2 compression
  • Entire device (?)
  • UDIF stub (?)
  • DVD/CD master
  • Sparse

(These were also taken from the manpage for hdiutil.)


Numerous other formats have existed for many years — specifically zip (on Windows) and gzip and bzip2 (on UNIX and Linux) — and StuffIt Expander has supported all of them since 3.0 (bzip2 since maybe 5).

But in OS X, StuffIt Expander (which came with the OS until Tiger) showed its age. Versions 6-8 were slow and ugly. This got better with version 9, but by that time, StuffIt Expander lost to the alternative that also came with the OS: Disk Copy (which merged with Disk First Aid and Drive Setup to form Disk Utility in Jaguar).

For several years, most software for Mac OS X was distributed in the form of a zlib-compressed dmg.

But now things have deteriorated.