10.3: A script to create a segmented disk image

Nov 16, '03 12:28:00PM

Contributed by: mahakali

In Jaguar, we can create segmented disk image using Disk Copy but yesterday when I was about to archive my files, I couldn't find a way to do this in Panther. But I'm not quite sure if it was just me or not. So I created a script that'll create a disk image and then segment it into smaller chunks.

Read the rest of the hint for the script...

Copy and paste this script below into Script Editor and save the script as an application somewhere. To use it, just drop a folder onto this script application.


on open (theItem)
  try
    set folderName to name of (get info for theItem)
    set imageName to folderName & "_temp.dmg"
    set theSource to POSIX path of theItem
    set theDestination to POSIX path of ¬
     (choose folder with prompt "Where do you want to save this thing?")
    set dmgPath to theDestination & imageName as string
    set segmentPath to theDestination & folderName as string
        
    display dialog "Enter the size of segments:" default answer ¬
     "690" buttons {"MB", "GB", "Cancel"} default button 1
    if the button returned of the result is "MB" then
      set theSize to (the text returned of the result) & "m"
    else if the button returned of the result is "GB" then
      set theSize to (the text returned of the result) & "g"
    end if
         
    with timeout of 3600 seconds
      do shell script "hdiutil create -srcfolder '" & ¬
       theSource & "' '" & dmgPath & "' ;
      hdiutil segment -segmentSize " & theSize & " -o '" & ¬
       segmentPath & "' '" & dmgPath & "' ;
      rm -r '" & dmgPath & "'" (* this line will erase temporary file. 
      You can delete this line if you'd like to keep the file *)
          
    end timeout
    beep 2
          
    on error the errMsg number the errNmb
    if the errNmb is not -128 then
      set the errTxt to "Error: " & the errNmb & ". " & the errMsg
      display dialog the errTxt buttons {"Cancel"} default button 1
    else
      error number -128
    end if
  end try
end open

This script is still not comparable to what Jaguar Disk Copy can do, though. Disk Copy would create segments with certain volume size while this script will segment a disk image into certain size. So if you'd like to archive them to CDs, for example, you need to burn the segmented disk image as files, not as volumes. If you know any other tricks, or if you can confirm that Panther did not take the segmenting feature away, I'd be very very happy to know. Thanks!

Comments (8)


Mac OS X Hints
http://hints.macworld.com/article.php?story=2003111007025349