Run script in background with hdiutil

I launch a new call concerning this problem.

set diskImage to POSIX path of "/Users/k2103/Desktop/iBook.sparseimage"
do shell script "/usr/bin/hdiutil compact " & quoted form of diskImage

I use this script (saved as ScriptName.app) to compact the sparseimages updated by my backup program (SuperDuper). It’s because the target image grows when the source grows, but does not decrease when the source decreases.

The script works very well, but I would like it integrated into the program and run automatically. SuperDuper makes it possible to thus integrate a script in the sequence of its operations.

Here are the sequence of the last operations of SuperDuper.

  1. After Successful Copy

Make iBook-01 bootable
Restores Spotlight state on iBook-01
Run shell script ScriptName.app
Unmount iBook-01

But the script cannot be carried out at that moment because the image is not yet unmounted.
It should run in background during about 30 seconds without doing nothing to let the image be unmounted by SD and then executes its task.

I made several tries but I did not find yet.
Need some help.

I do this (as part of a SuperDuper! script)


	tell application "Finder" to eject disk "ACB-External"
	-- wait for it
	repeat until (list disks) does not contain "ACB-External"
		delay 2
	end repeat

Fine, looks well.
But I apprehend an error in the continuation of the program when it’ll arrives at the step:

Unmount iBook-01

I’ll test it and return.

Thank you infinitely

You don’t “unmount” an external drive or server, you “eject” it.

Fantastic! :slight_smile:

You are right! I will have to learn the difference between “eject” and “unmount”.

The program works very well. I however had to add a “delay 30” because I sometimes got an error message “hdiutil: compact failed - Resources occupied”.

Here is the result:

tell application "Finder" to eject disk "iBook-01"
-- wait for it
repeat until (list disks) does not contain "iBook-01"
	delay 2
end repeat
delay 30
set diskImage to POSIX path of "/Volumes/SMARTDISK/Sauvegardes SuperDuper!/iBook-01.sparseimage"
do shell script "/usr/bin/hdiutil compact " & quoted form of diskImage

As improvement, I would like that script displays something of its progression and the result of its operation.

Thank you sincerely.

Unless you use BP Progress (in ScriptBuilders), or own 24UAppearance or Extra Suites, try Pseudo Progress Bar in Code Exchange, or run this as an AppleScript Studio application, there’s no way to show a progress bar except by guessing or simulating one because hdiutil doesn’t give any feedback while it’s running.
You could just use a dialog after your “do shell script” statement to let you know it was done.

However, when I run hdiutil compact from Terminal I get this result:

Last login: Sat Mar 17 16:56:56 on ttyp1
Welcome to Darwin!
You have new mail.
iMac-de-Luc-Morin:~ lucmorin$ hdiutil compact /Volumes/SMARTDISK/Sauvegardes\ SuperDuper!/Test.sparseimage
Initialisation…
Recherche d’espace disponible…

Récupération d’espace disponible…

Finalisation…
iMac-de-Luc-Morin:~ lucmorin$

And if I run the script, not compiled, from the script editor I get this result:

“Initialisation…
Recherche d’espace disponible…
Récupération d’espace disponible…
Récupéré 229 MB/37.5 GB (0.6%)
Finalisation…”

Wouldn’t be possible to make these results displayed by the compiled script?

I take note of your various suggestions and, while waiting, I will be ok with a message saying it is done, as you suggest.

Thank you, and greetings from Québec (sorry for my english)