Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

10.4: Compact sparse disk images via contextual menu Desktop
The following Automator workflow will simplify compacting a sparse disk image. You need to occasionally compact sparse disk images, because while they will grow automatically as you add files, they won't shrink when you delete files. Open Automator in Applications Folder, and create this workflow:
  1. Finder Library » Get Specified Finder Items Action
  2. Finder Library » Filter Finder Items, and select Name Extension is equal to sparseimage.
  3. Automator Library » Run Shell Script and select Pass input as arguments and replace the sample script with hdiutil compact $@.
Save as Plugin for Finder (name it Compact Sparse Disk Image). In the Finder, select a sparse disk image and ctrl-click, go to the Automator entry, and select Compact Sparse Disk Image. That's it!
    •    
  • Currently 2.17 / 5
  You rated: 3 / 5 (6 votes cast)
 
[14,085 views]  

10.4: Compact sparse disk images via contextual menu | 14 comments | Create New Account
Click here to return to the '10.4: Compact sparse disk images via contextual menu' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.4: Compact sparse disk images via contextual menu
Authored by: Nem on Mar 29, '07 08:12:25AM
Hmm.. Doesn't work with encrypted sparse disk images.

This isn't terribly bothersome to me. Another (more cumbersome) solution, is to create a new encrypted sparse disk image and just copy everything from the old image to the new image. Disk is cheap nowadays, so I wouldn't bother with the time to do this unless I really had to. ;-)

---
Nem W. Schlecht
http://geekmuse.net/

[ Reply to This | # ]

10.4: Compact sparse disk images via contextual menu
Authored by: dpaight on Mar 29, '07 12:33:33PM

It works on my encrypted sparseimage. Perhaps you have to have the password set in your keychain before it will work on an encrypted image.



[ Reply to This | # ]
10.4: Compact sparse disk images via contextual menu
Authored by: Nem on Mar 29, '07 03:13:38PM
You may be correct - I do not have my encrypted, sparse image passkeys in Keychain. Seems more secure to me. ;-)

I guess I could add my passphrase to Keychain, compress my image, then remove my passphrase. Sounds about the same about of work as my solution. ;-)

---
Nem W. Schlecht
http://geekmuse.net/

[ Reply to This | # ]

10.4: Compact sparse disk images via contextual menu
Authored by: TonyT on Mar 29, '07 03:59:55PM

Works on my encrypted Sparse Images. (and I do not add the password to keychain).



[ Reply to This | # ]
10.4: Compact sparse disk images via contextual menu
Authored by: Nem on Mar 29, '07 08:25:53PM
$ hdiutil compact myencsparse.dmg
Initializing...
  At this point I'm prompted for my passphrase
Finishing...
hdiutil: compact failed - Function not implemented

Running 10.4.9, PPC. I renamed my image from ".sparseimage" to ".dmg" after I had originally created it. I tried changing it back and running the compact again, but still no dice.

---
Nem W. Schlecht
http://geekmuse.net/

[ Reply to This | # ]

10.4: Compact sparse disk images via contextual menu
Authored by: Angus on Mar 29, '07 11:57:28AM

Thanks, I've been meaning to find out a way to do this. My SuperDuper backups get huge and I've been compacting them via Terminal, but this is better. The Workflow is failing for me though, not sure why.



[ Reply to This | # ]
10.4: Compact sparse disk images via contextual menu
Authored by: TonyT on Mar 29, '07 04:05:37PM

Excellent! No need to open terminal or run an applescript, just right-click and select automator.



[ Reply to This | # ]
10.4: Compact sparse disk images via contextual menu
Authored by: silentaccord on Mar 30, '07 01:04:46AM

For those that are having trouble, try using Get Selected Finder Items for the first action instead of Get Specified Finder Items and for the shell script, select /bin/zsh as the shell. This is the only way I could get it to work.



[ Reply to This | # ]
10.4: Compact sparse disk images via contextual menu
Authored by: Anonymous on Mar 30, '07 11:26:56AM

Nope. Still cannot get this to work. Use ready made On My Command script instead. Best utility out there.



[ Reply to This | # ]
10.4: Compact sparse disk images via contextual menu
Authored by: Angus on Mar 30, '07 10:19:25PM
Thanks silentaccord. Using "Get Selected Finder Items" and the zsh shell worked.

On a related note, I found out that SuperDuper can run shell scripts upon completion, so I'll try automating it that way.
"Run shell script after copy completes"
See: http://bbs.applescript.net/viewtopic.php?pid=77246

[ Reply to This | # ]
10.4: Compact sparse disk images via contextual menu
Authored by: musickhead on May 29, '09 11:06:34AM

Nem points out that this doesn't work with encrypted images. Does anyone know how to provide the script with the necessary password? I don't think it can be done using arguments or variables or pipes. How do you catch the prompt for the password? The -stdinpass option doesn't seem to do anything. I would like to be able to do this so I can maintain the smallest possible backup of my files on a USB thumb drive.



[ Reply to This | # ]
10.4: Compact sparse disk images via contextual menu
Authored by: GlowingApple on Sep 11, '09 02:01:31PM
I believe echo -n "password" | hdiutil compact -stdinpass $@ should work.

---
--
~Jayson


[ Reply to This | # ]

10.4: Compact sparse disk images via contextual menu
Authored by: GlowingApple on Sep 11, '09 02:03:46PM

I should of course mention that this puts your password in the clear in the Automator script (anyone that has access to the script can read your password).

It would be much more secure to save the password in your Keychain instead.

---
--
~Jayson



[ Reply to This | # ]
10.4: Compact sparse disk images via contextual menu
Authored by: GlowingApple on Sep 11, '09 02:46:32PM
Sorry for the multiple posts, but I think I found a way to fix the encrypted image issues without having to store the password or post it in the clear in the script.

It seems that hdiutil prompts for a password from stdin by default. So the script will run, receive no input, and error out from an authentication failure. If you give hdiutil no option for input (by directing input from something like /dev/null), then it resorts to a graphical password prompt.

Use this code in the script and it should prompt for the password each time:
hdiutil compact $@ </dev/null

---
--
~Jayson


[ Reply to This | # ]