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.
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.
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.
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.