hdiutil: compact: Only one input file can be specified.

AppleScript error:
hdiutil: compact: Only one input file can be specified.

I would like to know why I receive this error message with that script?
The command works well in direct mode in Terminal.

set Spimage to (choose file)
do shell script "hdiutil compact $ Spimage"

I would be very grateful.

Model: iMac G5
AppleScript: 1.10.7
Browser: Safari 419.3
Operating System: Mac OS X (10.4)

Welcome!

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

Many thanks. So Quickly

It’s my first try. :slight_smile:

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”

I appreciate your generous assistance

Do either of these work for you?

do shell script "/bin/sleep 30; /usr/bin/hdiutil compact " & quoted form of diskImage

delay 30
do shell script "/usr/bin/hdiutil compact " & quoted form of diskImage

Incredible!
I test immediately.

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.

  1. After Successful Copy

Made iBook-01 bootable
Restored Spotlight state on iBook-01
Ran shell script Compact.app
Unmount iBook-01