simple applescript/terminal question

Discussion in 'Mac Programming' started by harleytat, Mar 24, 2010.

  1. harleytat macrumors newbie

    Joined:
    Jul 22, 2002
    #1
    I have a Drobo to which I backup five drives using SuperDuper as sparsebundles. I also regularly compact the sparsebundles using a simple Applescript that looks like this:

    Code:
    do shell script "hdiutil compact /Volumes/Drobo/'Drive 1.sparsebundle'"
    
    do shell script "hdiutil compact /Volumes/Drobo/'Drive 2.sparsebundle'"
    
    etc...
    However, I'd rather use grep/wildcards to compact EVERY sparsebundle on my Drobo, as I sometimes temporarily backup client drives to the Drobo as well. When I do "hdiutil compact /Volumes/Drobo/*.sparsebundle," the compact fails, as the terminal is trying to compact all of them simultaneously (which makes sense).

    My question: Is it possible to write a single terminal command that sequentially compacts all sparsebundles on a drive?
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    Yes.








    Oh, so you wanted a hint rather than the direct question answered? A combination if ls, xargs and your hdiutil command should do it.
     
  3. harleytat thread starter macrumors newbie

    Joined:
    Jul 22, 2002
    #3
    Thanks, Robbie, for the clue--but I'll take the full answer if you got it! :)
     
  4. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #4
    Well as I don't have a similar environment to test your code in this is just typed straight into the reply box: it might well not work.

    Code:
    ls -1 /Volumes/Drobo/*.sparsebundle | xargs -IREP hdiutil compact /Volumes/Drobo/REP
    
     
  5. mysterytramp macrumors 65816

    mysterytramp

    Joined:
    Jul 17, 2008
    Location:
    Maryland
    #5
    And this might work, too:

    Code:
    set bundleList to list files of "/Volumes/Drobo/"
    
    repeat with bl in bundleList
    	
    	do shell script "hdiutil compact /Volumes/Drobo/" & (quoted form of (bl as string))
    	
    end repeat
    mt
     

Share This Page