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


Click here to return to the 'I think I improved the script.' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
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 | # ]