Tuesday, February 9, 2010

#1 2007-03-16 10:36:57 pm

k2103
Member
From: Québec
Registered: 2007-03-10
Posts: 9

Run script in background with hdiutil

I launch a new call concerning this problem.

Applescript:

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

Offline

 

#2 2007-03-16 10:55:16 pm

Adam Bell
Administrator
From: Nova Scotia, Canada
Registered: 2005-10-04
Posts: 4175

Re: Run script in background with hdiutil

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

Applescript:


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


Scripts are tested on a PowerMac dual-core G5/2.3 running OS X 10.5.8 or MacBook Pro Intel Core 2 Duo running OS X 10.6.2

Filed under: Finder

Offline

 

#3 2007-03-16 11:27:58 pm

k2103
Member
From: Québec
Registered: 2007-03-10
Posts: 9

Re: Run script in background with hdiutil

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

Offline

 

#4 2007-03-17 08:16:59 am

Adam Bell
Administrator
From: Nova Scotia, Canada
Registered: 2005-10-04
Posts: 4175

Re: Run script in background with hdiutil

You don't "unmount" an external drive or server, you "eject" it.


Scripts are tested on a PowerMac dual-core G5/2.3 running OS X 10.5.8 or MacBook Pro Intel Core 2 Duo running OS X 10.6.2

Offline

 

#5 2007-03-17 10:36:32 am

k2103
Member
From: Québec
Registered: 2007-03-10
Posts: 9

Re: Run script in background with hdiutil

Fantastic!  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:

Applescript:

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.


Filed under: Finder

Offline

 

#6 2007-03-17 12:46:43 pm

Adam Bell
Administrator
From: Nova Scotia, Canada
Registered: 2005-10-04
Posts: 4175

Re: Run script in background with hdiutil

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.


Scripts are tested on a PowerMac dual-core G5/2.3 running OS X 10.5.8 or MacBook Pro Intel Core 2 Duo running OS X 10.6.2

Offline

 

#7 2007-03-17 05:24:55 pm

k2103
Member
From: Québec
Registered: 2007-03-10
Posts: 9

Re: Run script in background with hdiutil

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)

Offline

 

Board footer

Powered by FluxBB

[ Generated in 0.204 seconds, 10 queries executed ]

RSS (new topics) RSS (active topics)