The Cave

29 Nov

Disk Image Backgrounds

It sounds so simple. Just create a disk image with a file in the right location and voila.

The only difference between theory and practice is, in theory, there is no difference between theory and practice.

Mozilla’s pkg-dpkg makes it easy to create a Mac OS X disk image. Though in their infinite wisdom didn’t add any ‘version identifier’ to the script so you have no idea which ‘version’ you’re using unless you find the Mozilla repository and diff your source. I’m using the latest from Dec 12, 2007 with 1520 lines. But I digress.

So you try to create the .dmg with –copy MyBackground.png:/.background/background.png only to learn it never shows up when you open the disk. You then spend countless hours trying various things and maddeningly searching the web trying to understand the fragmented (and mostly incorrect) answers until, finally! The magic sauce stands revealed. A major thanks to this and this and this for the key — it’s the .DS_Store file.

Sadly, this is a binary file with no documented (or undocumented) file format nor APIs or tools to programmatically manipulate one. BUT, you can create the disk image programatically with the right background, you just need a small manual setup step to create the right .DS_Store up front – like any other ‘source’ file.

Everyone talks about creating a “read-write disk image” but it’s confusing as all hell. I create a BZip2 disk image (UDBZ) – is that read-only or writeable? Turns out your local copy is writeable. Here’s what I did to create hHasher 1.0:

  1. Create the disk image including the background image at /.background/background.png
    ./pkg-dpkg –source ./diskimage –target ./hHasher-1.0.dmg –format UDBZ –volname hHasher-1.0 –resource ./license/sla.r –icon ./image/DiskImage.icns –idme –copy ./image/DiskImage_DS_Store:/.DS_Store –mkdir /.background –copy ./image/DiskImageBackground.png:/.background/background.png –symlink /Applications:/Applications
  2. Mount the disk image
    open hHasher-1.0.dmg
  3. Show the view options
    View/Show View Options (or Cmd-J if you prefer)
  4. Change to list view if not already there (View/as Icons, or Cmd-1 if you prefer)
  5. Check the ‘Always open in list view’ option
  6. Change the ‘Arrange by’ combo box to ‘None’
  7. Change the ‘Background’ option to ‘Picture’
  8. Select the background image via the ‘Select’ button, hit Cmd-Shift-G to change to the background directory (e.g. /Volumes/hHasher/.background) and select the background image (background.png)
  9. Layout the icons as you desire. You may want to alter the ‘Icon size’ and ‘Grid spacing’ options.
  10. Eject the disk image! Finder only flushes these changes to disk when the disk dismounts so you MUST unmount the disk image to get the updated .DS_Store file.
  11. Open the disk image again
  12. Save the .DS_Store to your build environment
    cp /Volumes/hHasher/.DS_Store ~/projects/jHasher/install/images/DiskImage_DS_Store

Voila!

At this point you have a .DS_Store you can feed into your pkg-dpkg command line and automate your dmg creation. Treat the .DS_Store as source (i.e. manually update as and when necessary) and all is well.

Hideously poorly documented and understood, but it’s possible to figure out. Hopefully this will make your day notably less painful than mine were.

FacebookGoogle GmailGoogle BookmarksTechnorati FavoritesTwitterHotmailYahoo MailYahoo MessengerWordPressStumbleUponRedditEmailInstapaperGoogle+Share

Comments are closed.

© 2014 The Cave | Entries (RSS) and Comments (RSS)

GPS Reviews and news from GPS Gazettewordpress logo