You need to convert the alias returned by choose file into a POSIX path. (e.g “Hard Drive:Folder:Disk Image” changes to “/Folder/Disk Image”.) Also, you usually need to quote a path when using a shell script.
Try something like this:
choose file with prompt "Compact this sparse disk image:" without invisibles
set diskImage to POSIX path of result
do shell script "/usr/bin/hdiutil compact " & quoted form of diskImage
It was the first step of my project.
This script must be called at the end of my backup program (SuperDuper) when the image is not yet unmounted.
It must run in background during 30 seconds to let the image be unmounted by SD.
I thus adapted it but I don’t know exactly the syntax of the commands to make it turn in background during a certain time.
set diskImage to POSIX path of "/Users/k2103/Desktop/iBook.sparseimage"
do shell script "!/bin/sh"
do shell script "nohup /bin/bash -c sleep 30"
do shell script "/usr/bin/hdiutil compact " & quoted form of diskImage
I got the message “sh: line 1: !/bin/sh: No such file or directory”
and “usage: sleep seconds”
Unfortunately, there is a problem.
The instruction should suspend the script during 30 seconds without also stopping the main program. It must thus turn in background while SuperDuper finishes its operations.
It is the key of the problem.
I thought that it was the role of those commands:
!/bin/sh
nohup /bin/bash -c
Here are the sequence of the last operations of SuperDuper.
After Successful Copy
Made iBook-01 bootable
Restored Spotlight state on iBook-01
Ran shell script Compact.app
Unmount iBook-01