Store Developer docs on a compressed disk image

May 03, '07 07:30:00AM

Contributed by: Anonymous

I just got done re-installing OS-X (an old Microsoft habit, I guess), and was installing XCode when I realized that almost half of the installation size of XCode is the documentation. I need that documentation, but hate to see 1.3 Gb of my hard drive gobbled up by something that is:

  1. Very compressible
  2. Not demanding on resources
  3. Only rarely used
So I hatched the hare-brained idea to compress it -- and it worked! I've cleaned up the code, so fire up Terminal and do this:
 $ cd /Developer
 $ sudo hdiutil create -srcfolder "ADC Reference Library" 
   -format UDBZ DevLibrary.dmg
That will build the compressed reference library in the Developer folder. Once you are done, delete the "old" reference folder, and make an empty placeholder for later:
 $ sudo rm -rf "ADC Reference Library"
 $ mkdir "ADC Reference Library"
Note: I didn't sudo the mkdir command on purpose, to keep the following Folder Action from prompting me for a password just to open the Developer documentation.

Now once you're done, you can attach to it using hdiutil:

 $ hdiutil attach -mountpoint /Developer/ADC Reference Library 
   /Developer/DevLibrary.dmg
That's it! It's not a read/write volume, but that doesn't seem to be a problem. Be patient while it checksums the file on the first mount, it will go faster once everything checks out.

I also attached a folder action to the /Developer folder that mounts the volume automatically -- that way when I navigate to the Xcode app, it mounts the compressed image for me on the way. Open up Script Editor and cut and paste this code in (don't mind the sloppy code; I'm a script newbie...):

on opening folder this_folder
  tell application "System Events"
    if file "/Developer/ADC Reference Library/index.html" exists then
      -- display dialog "it exists!" --used for testing
    else
      do shell script "hdiutil attach -mountpoint /Developer/ADC\ Reference\ Library/ /Developer/DevLibrary.dmg"
    end if
  end tell
end opening folder

Note that the double backslashes are not typos; AppleScript requires them to handle the backslash properly. Save the script to wherever you want (stock Apple Folder Actions are located in /Library » Scripts » Folder Action Scripts). Control-click on the Developer folder and Enable Folder Actions if they aren't already. Control-click again, select Add Action, and navigate to the saved script above, and you should have an automatically mounting compressed reference library!

[robg adds: Geeklog ate all the backslashes in the original submission, but I think I've put them all back where they need to be -- as a gentle reminder, please use the [code] [/code] tag pair when including code (that will protect the backslashes), and include your email address if posting anonymously, so I can contact you with questions!]

Comments (29)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20070502043036544