automating burning an .img file to disk

Hi everyone! This is my first post here, and also my first real attempt at applescript. I am trying to be able to drag an .img file to the icon and have the system burn the image to disk. So basically what I have done so far is write out the sudo code for what I normally do to burn the image to disk. I usually mount the image, then open disk utility, click on the mounted image and then click burn, then click ok, wait for the burn and verify to complete, then click ok in the dialogue box that says “burn successful” and then quit Disk Utility.

I also have this code that is supposed to select the mounted image once Disk Utility is open:

tell application "Disk Utility" 
    activate 
end tell 
tell application "System Events" 
    tell process "Disk Utility" 
        tell row of outline of scroll area of window "Disk Utility" 
            click static text 4
        end tell 
    end tell 
end tell

So, how do I tell it to wait for the burn complete? And the code above seems to not work

Model: MacBook
AppleScript: 2.0
Browser: Safari 523.15
Operating System: Mac OS X (10.5)

There’s a unix command line application “hdiutil” that should help you do it easier. I haven’t tried it but something like this should work.

-- save this script as an application
-- when an image file is dropped on the application icon the image file will be burned to disk.

-- this happens when app is double-clicked
on run
	display dialog "Drop an image file on me to burn it!" buttons {"OK"} default button 1 with icon note
end run

-- this happens when items are dropped on the application
on open theItems
	-- make sure only one image file is dropped on the icon
	if (count of theItems) > 1 then
		display dialog "Please only drop one image file at a time on me" buttons {"OK"} default button 1 with icon note
		return
	end if
	
	-- make sure only an image file was dropped on the icon
	set thisItem to item 1 of theItems
	tell application "Finder" to set theExt to name extension of thisItem
	if theExt is "img" or theExt is "dmg" then
		-- burn the image
		do shell script "hdiutil burn " & quoted form of POSIX path of (thisItem as text)
	else
		display dialog "Please only drop an image file on me" buttons {"OK"} default button 1 with icon note
		return
	end if
	
	-- tell you that the burn is finished
	display dialog "The image file has been burned" buttons {"OK"} default button 1 with icon note
end open

Sweet, that works just great. Looks like I need to familiarize myself more with Unix commands. I’m going to post the script again with some of the dialogues changed. But mostly I wanted to show how to eject the slot-load disk after burning (since I had some trouble finding how to do it), so here we go:


-- This script is strictly an app.
-- when an image file is dropped on the application icon the image file will be burned.

-- this happens when app is double-clicked
on run
	display dialog "Don't click me, feed me!" buttons {"Ok?'"} default button 1 with icon note
end run

-- this happens when items are dropped on the application
on open theItems
	-- make sure only one image file is dropped on the icon
	if (count of theItems) > 1 then
		display dialog "One at a time please :)" buttons {"Ok?"} default button 1 with icon note
		return
	end if
	
	-- make sure only an image file was dropped on the icon
	set thisItem to item 1 of theItems
	tell application "Finder" to set theExt to name extension of thisItem
	if theExt is "img" or theExt is "dmg" then
		-- burn the image
		do shell script "hdiutil burn " & quoted form of POSIX path of (thisItem as text)
	else
		display dialog "One at a time please :)" buttons {"Oh, all right..."} default button 1 with icon note
		return
	end if
	
	-- tell you that the burn is finished
	do shell script ("drutil eject")
	display dialog "The image file has been burned!" buttons {"OK"} default button 1 with icon note
	say "The image file has been burned!"
	
end open


Very good! I’m glad it worked for you. One thing I see though. The following line isn’t right:

display dialog “One at a time please” buttons {“Oh, all right…”} default button 1 with icon note

You’ll note that this line is in an if statement. The if statement checks to make sure that an “img” or “dmg” file has been dropped on the application. If something else is dropped (for example a “txt” file) then this dialog box will be shown… so you need to tell the user only to drop img or dmg files at that point. It has nothing to do with the number of files dropped on the application, only the type of files that were dropped.

Later!

Haha… silly me. I tend to over-use the find and replace features :slight_smile: There is only one thing keeping this script from perfection, and that is a burn progress bar. That would be really nice, however i don’t believe that is possible with the unix command that is used in the script. oh well, it’s automated now, so who am I to complain!

Thanks so much for your help!