Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

10.3: A script to create a segmented disk image System

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!

    •    
  • Currently 1.50 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (6 votes cast)
 
[14,222 views]  

10.3: A script to create a segmented disk image | 8 comments | Create New Account
Click here to return to the '10.3: A script to create a segmented disk image' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.3: A script to create a segmented disk image
Authored by: dfbills on Nov 16, '03 03:06:14PM

You should be able to use Disk Copy from Jaguar to accomplish this..



[ Reply to This | # ]
10.3: A script to create a segmented disk image
Authored by: bluehz on Nov 17, '03 12:34:04AM
People are claiming they can use the Jaguar version of Disk Copy (which I prefer over the new Panther Disk Utility), but every time I try to use the old Disk Copy it crashes. Any solutions?
**********

Host:       ****
Date/Time:  2003-11-17 00:30:38 -0500
OS Version: 10.3.1 (Build 7C107)

Command:    Disk Copy (/Applications/Utilities/Disk Copy.app/Contents/MacOS/Disk Copy)
PID:        1064
Thread:     0

Exception:  EXC_BAD_ACCESS (0x0001)
Codes:      KERN_INVALID_ADDRESS (0x0001) at 0xbc000000

Thread 0 Crashed:
 #0   0x90831234 in objc_msgSend (objc_msgSend + 20)
 #1   0x0001dce8 in 0x1dce8
 #2   0x909f1c54 in NSPopAutoreleasePool (NSPopAutoreleasePool + 356)
 #3   0x90a01d2c in __NSFireDelayedPerform (__NSFireDelayedPerform + 360)
 #4   0x90194848 in __CFRunLoopDoTimer (__CFRunLoopDoTimer + 244)
 #5   0x90191ba8 in __CFRunLoopRun (__CFRunLoopRun + 1480)
 #6   0x901960bc in CFRunLoopRunSpecific (CFRunLoopRunSpecific + 328)
 #7   0x927d5ecc in RunCurrentEventLoopInMode (RunCurrentEventLoopInMode + 172)
 #8   0x927dc640 in ReceiveNextEventCommon (ReceiveNextEventCommon + 380)
 #9   0x927fe6d0 in BlockUntilNextEventMatchingListInMode (BlockUntilNextEventMatchingListInMode + 96)
 #10  0x92dd2a80 in _DPSNextEvent (_DPSNextEvent + 384)
 #11  0x92de93fc in -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] (-[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 116)
 #12  0x92dfd730 in -[NSApplication run] (-[NSApplication run] + 540)
 #13  0x92eb9a1c in NSApplicationMain (NSApplicationMain + 464)
 #14  0x00004d3c in 0x4d3c
 #15  0x00004bbc in 0x4bbc


[ Reply to This | # ]
10.3: A script to create a segmented disk image
Authored by: mahakali on Nov 17, '03 12:56:49PM

I also tried using Jaguar Disk Copy. I was able to launch it but when I tried making an image using it, it crashed.



[ Reply to This | # ]
10.3: A script to create a segmented disk image
Authored by: timcrawf on Nov 18, '03 12:42:53AM

Using Disk Copy, I was just able to create a disk image from a folder, via drag and drop, mount it using the same method and then convert it from compressed to read/write.
I am using Panther, installed via erase and install on a rev A 12" AlBook



[ Reply to This | # ]
More DiskUtility Image Options
Authored by: saint.duo on Nov 16, '03 07:21:54PM
I'm quoting from a comment in a previous hint: Doesn't seem to affect new images, but does affect conversion options.

"Authored by: njitkoff on Fri, Nov 14 '03 at 01:36PM

you can also use

defaults write com.apple.DiskUtility advanced-image-options 1

to have access to just the other image types"

---
--
duo

[ Reply to This | # ]

resizing??
Authored by: cynikal on Nov 17, '03 11:26:46PM

How the HELL do you resize an image?! I copied DiscCopy from a jaguar installation, but that's a piss poor workaround..



[ Reply to This | # ]
resizing??
Authored by: cilly on Apr 22, '04 01:51:10PM

In Disk Utility there is the option to resize already built in, but Apple commented that out. Browse thru the package to find it...

---
cilly @ http://www.cilly.dyndns.org/



[ Reply to This | # ]
I think I improved the script.
Authored by: Lectrick on Jan 16, '04 03:46:03AM
I believe I improved the script. What I added:
1) Handling of multiple dropped items
2) If the item is a disk image, split it. If it is a folder or non-image file, create a temporary image using it first, then split that image. (The latter is the only thing the script above did no matter what you dropped on it- so if you dropped an image file, it would put it inside ANOTHER image file.)

on open (DroppedItems)
	set theDestination to POSIX path of 
		(choose folder with prompt "Where do you want to save the segments?")
	display dialog "Enter the size of segments for dropped files:" 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
	repeat with theItem in DroppedItems
		try
			set ItemInfo to info for theItem
			set folderName to name of ItemInfo
			set FileTypeOfItem to file type of ItemInfo
			set FileExtensionOfItem to name extension of ItemInfo
			set isImage to false
			if FileTypeOfItem is "devi" or FileExtensionOfItem is "dmg" then
				set isImage to true
			end if
			set imageName to folderName & "_temp.dmg"
			set theSource to POSIX path of theItem
			if isImage then
				set dmgPath to theSource
			else
				set dmgPath to theDestination & imageName as string
			end if
			set segmentPath to theDestination & folderName as string
			
			with timeout of 3600 seconds
				if not isImage then
					do shell script "hdiutil create -srcfolder '" & 
						theSource & "' -tgtimagekey zlib-level=9 '" & dmgPath & "'"
				end if
				do shell script "hdiutil segment -segmentSize " & theSize & " -o '" & 
					segmentPath & "' '" & dmgPath & "'"
				if not isImage then
					do shell script "rm '" & dmgPath & "'" -- removes the temp image
				end if
			end timeout
			
		on error the errMsg number the errNmb
			if the errNmb is not -128 then
				if the errNmb is 1 then
					set the errTxt to "Error: File already exists. 
					For dropped image files, you have to pick a different target directory."
				else
					set the errTxt to "Error: " & the errNmb & ". " & the errMsg
				end if
				display dialog the errTxt buttons {"Cancel"} default button 1
			else
				error number -128
			end if
		end try
	end repeat
	beep 2 --done
end open

---
In /dev/null, no one can hear you scream

[ Reply to This | # ]