Compacting Sparse Disk Images

A lot of you have seen my screencast on how to make an encrypted sparse disk image. As I explained in the screencast, sparse disk images grow when add files into them but don't shrink when you pull files out. As my sparse disk images used to bloat I would occaisionnally make a new one and copy the files into it and discard the old image. Recently however I discovered an automator workflow that compacts an existing sparse image without requiring you to take all those insane steps I used to. So lets walk through it now.

Step One ... Load Automator


Fig01_small.jpg


Now some of you may be Automator veterans but for me it is just that funny looking icon I always pass over.

Step Two ... First Script


Compact Sparse Image 1.jpg


Click on the "Finder" category in the Library column then click and drag "Get Selected Finder Items" from the Actions Column into the work area of Automator.

Step Two ... Second Script


Compact Sparse Image-1.jpg


Click on the "Automator" category in the Library column then click and drag "Run Shell Script" from the Actions Column into the work area of Automator.

Step Three ... Change Pass Input


Compact Sparse Image-2.jpg


Change the "pass input" drop down from "to sdnin" to "as arguments"

Step Four ... Remove Text from the Shell Window


Compact Sparse Image-3.jpg



Step Five ... Fill in the Window


Compact Sparse Image-4.jpg


Type in the following in the window....

hdiutil compact "$@"

Step Six ... Save It


Go to Automator's File menu and "Save as Plug-in". Give it a name like "Compact Sparse Image". Also make sure "Plug-in for:" category says "Finder".

Automator.jpg


Using the Workflow

1. Find your sparse image in the finder.
2. Make sure it is unmounted
3. Cntrl(Right)-Click, Mouse down to Automator and run your script.

Now all of the above probably sounds like a lot of work but it really is not. Once you have it set up you can regularly compact your sparse images. Let me know if it works for you.



Technorati Tags:
, ,