Applescript to Burn Audio CD from Filemaker

I store MP3 files in a Filemaker database. After using information posted on this site I came up with the script below to burn audio CD’s. Works well, but it is not very elegant. Also wanted to make sure I have not overlooked any user errors. Any suggestions would be welcomed

–be sure to change CD handling on computer to ignore blank CD and Audio CD

– get parameters from Filemaker Pro I need for this script
tell application “FileMaker Pro”
tell database 1
set current_record to ID of current record as integer --the record ID of the record calling this script
end tell
tell table “Preferences”
tell record 1
set database_folder to cell “_cMyFolder_AS” --location of database on Hard Drive
set toBurnSound to cell “ToBurnSound” --sound saved by simplesound plugin by 24U software
– gwarn is a setting in Filemaker Pro database to know how much feedback the user wants
set gwarn to cell “gwarned” as number
end tell
end tell
end tell

set myFilename to database_folder & “savedaudio:” & toBurnSound --opening Filemaker script creates a folder savedaudio in the same folder as the database file
set fileStatus to false

–find out if the file exists
tell application “Finder”
try
set workingFile to file myFilename --does file exist

	--make sure the file is not too large to record to a CD
	set fileSize to size of workingFile
	set dataSize to round (((fileSize * 8.832) / 1000) / 1000)
	if dataSize < 692 then
		set this_folder to database_folder & "ToBurn"
		set burn_folder to POSIX path of this_folder
		--copy file to the folder to be burned
		set delete_this_File to (duplicate workingFile to this_folder)
		set fileStatus to true
		
	else
		display dialog "The size of the folder, " & dataSize & " MB, is larger than a typical writable CD." & return & "You will need to make a recording that is shorter if you want to record it to a CD." buttons {"OK"} default button "OK" with icon caution
		--Pass result of Burn_the_CD routine to Filemaker pro so it be used later in a Filemaker script
		tell application "FileMaker Pro"
			tell table "Preferences"
				tell record 1
					set cell "ToBurnSound" to "Sound file too Large"
				end tell
			end tell
		end tell
	end if
	
on error error_message number error_number
	tell me to display dialog "The following error message has occured:" & return & error_message & return & "Please notify the administrator." buttons {"OK"} default button "OK" with icon stop
	--Pass result of Burn_the_CD routine to Filemaker pro so it be used later in a Filemaker script
	tell application "FileMaker Pro"
		tell table "Preferences"
			tell record 1
				if error_number is -1728 then
					set cell "ToBurnSound" to "File not Found"
				else
					set cell "ToBurnSound" to error_message & return & "Error number " & error_number
				end if
			end tell
		end tell
	end tell
end try

end tell

if fileStatus then
set user_cancel to Burn_the_CD(burn_folder)

--Pass result of Burn_the_CD routine to Filemaker pro so it be used later in a Filemaker script
tell application "FileMaker Pro"
	tell table "Preferences"
		tell record 1
			set cell "ToBurnSound" to user_cancel
		end tell
	end tell
end tell

tell application "Finder"
	delete delete_this_File --delete old file
end tell

end if

on Burn_the_CD(burn_folder)
try
display dialog “Please insert a blank, writable CD THEN click the " & quote & “OK” & quote & " button” with icon note
on error number -128
return “user canceled”
–capture if user canceled (error number -128)
end try
–delay so user can put in CD and it can mount
delay 5
repeat 10 times
–if after a total of 25 seconds no disc is mounted assume user problem
set BlankCD to checkBlankCD() – true, if a blank CD/DVD inserted
if BlankCD then
exit repeat
else
delay 2
end if
end repeat
if BlankCD then --a valid blank cd was inserted

	--need timeout so script will not timeout before file is converted
	with timeout of (10 * minutes) seconds
		set Burn_the_disk to do shell script "drutil -drive internal burn -audio " & quoted form of burn_folder as string
	end timeout
	if Burn_the_disk contains "Burn completed" then
		return "Burn Successful"
	else
		return "Burn Error"
	end if
	
	--need to check what happens when disk burn is completed with errors
	--need to check how long it takes to burn and redo filemaker script to accurately relfect the approximate burn time
	--may be use my old check process subroutine to see if drutil is still running if we run it in background
else
	
	try
		do shell script "diskutil eject disk1"
	on error
		tell me to display dialog "You did not insert a Blank CD! Please Find a blank CD and try again." buttons {"OK"} default button "OK" with icon caution
		return "NO Blank CD"
	end try
	tell me to display dialog "The CD you inserted is not a blank disc! Please Find a blank CD and try again." buttons {"OK"} default button "OK" with icon caution
	return "NOT a Blank CD"
end if

end Burn_the_CD

on checkBlankCD()
try
do shell script “diskutil list | grep ‘0 B’”
return true
on error
return false
end try
end checkBlankCD

Model: MacBook
AppleScript: 2.1.1
Browser: Safari 530.17
Operating System: Mac OS X (10.6)