To shrink a dynamically growing drive image (the parameter -stdinpass is need for encrypted images):
[shell] hdiutil compact -stdinpass file.sparseimage[/shell]
On a laptop running on battery power the parameter -batteryallowed is needed, otherwise there will be an error “function not implemented”.