Remote CD burning (Folder Action script)

Lab gets a new Mac mini to use as a headless server. Lab users want to be able to burn CDs with mini’s combo drive. I get the task of figuring this all out!

The script burns ISO files and converts and then burns DMG files and deletes all other files. But it does NOT do any other checking (e.g.: file size, disc inserted, etc). I also put in a little bit of code to eject a non-burnable CD incase some L-user inserts one into the mini accidentally. It does not require any special libraries or add-ons.

And I wrote a very short “wait untill copying done” routine (19 lines). All the other ones I saw while working on this script were ridiculously long.

There are lots of hard-coded paths in here so watch out for that. I could probably fix that and tighten-up some parts of the code but meh

Released to the Public Domain so feel free to shamelessly rip it off and use it anyway you please. Tho I would appriciate an email if you find this usefull!


(* Burn_to_cd.scpt - Written by Steven Hunter (hunters@NOSPAMpurdue.edu)
Folder Action script that burns DMG-UDIF and ISO-9660 images to CD.
Released to the Public Domain; reproduce and use as you please. *)

on adding folder items to this_folder after receiving these_items
	
	repeat with i from 1 to number of items in these_items
		set this_item to item i of these_items
		set file_path to the quoted form of the POSIX path of this_item
		set item_info to the info for this_item
		set l_size to -1
		set copy_done to false
		
		repeat while copy_done is false
			tell application "System Events"
				set c_size to size of this_item
			end tell
			
			if c_size > l_size then
				set l_size to c_size
				delay 5
			else
				tell application "System Events"
					set c_size2 to size of this_item
				end tell
				if (c_size2 is not equal to c_size) and (l_size is not equal to c_size) then
					delay 5
				else
					set copy_done to true
				end if
			end if
		end repeat
		
		(* Some strings for use later *)
		set eject_text to "A request to eject a CD was received. Any error messages will follow."
		set dmg_text to "Beginning to process a DMG file."
		set iso_text to "Beginning to burn an ISO image."
		
		(* If a non-blank disc is inserted, then you can eject it. *)
		if the name of item_info is "Eject_CD.txt" then
			do shell script ("/bin/rm -f /burn_folder/Last_Burn.txt")
			do shell script ("/bin/echo " & eject_text & " >>  /burn_folder/Last_Burn.txt")
			do shell script ("/usr/sbin/diskutil eject /dev/disk2 >>  /burn_folder/Last_Burn.txt")
		end if
		
		(* If it's a DMG file, we have to do some pre-processing before burning it. *)
		if the name extension of item_info is "DMG" or "dmg" then
			do shell script ("/bin/rm -f /burn_folder/Last_Burn.txt")
			do shell script ("/bin/echo " & dmg_text & " >>  /burn_folder/Last_Burn.txt")
			do shell script ("/usr/bin/hdiutil makehybrid -o /burn_folder/do_not_use/stage1.iso " & file_path & " -hfs -iso -joliet >>  /burn_folder/Last_Burn.txt")
			do shell script ("/usr/bin/hdiutil convert -format UDTO -o /burn_folder/do_not_use/converted_image /burn_folder/do_not_use/stage1.iso >>  /burn_folder/Last_Burn.txt")
			do shell script ("/usr/bin/hdiutil burn -eject -verifyburn /burn_folder/do_not_use/converted_image.cdr >> /burn_folder/Last_Burn.txt")
			do shell script ("/bin/rm -f /burn_folder/do_not_use/converted_image.cdr")
			do shell script ("/bin/rm -f /burn_folder/do_not_use/stage1.iso")
			do shell script ("/bin/rm -f " & file_path)
		end if
		
		(* If it's an ISO, we can just burn it straight to a disc. *)
		if the name extension of item_info is "ISO" or "iso" then
			do shell script ("/bin/rm -f /burn_folder/Last_Burn.txt")
			do shell script ("/bin/echo " & iso_text & " >>  /burn_folder/Last_Burn.txt")
			do shell script ("/usr/bin/hdiutil burn -eject -verifyburn" & file_path)
			do shell script ("/bin/rm -f " & file_path)
		end if
		
		(* If the file doesn't match any of the above, delete it *)
		do shell script ("/bin/rm -f " & file_path)
		
	end repeat
end adding folder items to

EDIT: Corrected email address in comments