I have written the following script for burning audio files whose location is stored in Filemaker Pro to a CD using the do shell script "drutil -drive external burn -audio -eject ".
The script is called from within Filemaker Pro and works great. The problem is that the burning process can take up to 10 minutes depending on how large the audio file is. The user doesn’t get any feedback that something is happening. I can’t seem to figure out how to send the user feedback over this 10 minute period.
Also if you see a way to streamline the script particularly the “on checkdiscstatus()” handler seems to run slow that would be appreciated.
thank you in advance
Kevin
–be sure to change CD handling on computer to ignore blank CD and Audio CD
–use shell script to change setting
– do shell script “defaults write com.apple.digihub com.apple.digihub.blank.cd.appeared -dict action 100”
– for “open in Finder”
– do shell script “defaults write com.apple.digihub com.apple.digihub.blank.cd.appeared -dict action 1”
– for “ignore”
– do shell script “defaults write com.apple.digihub com.apple.digihub.blank.cd.appeared -dict action 2”
– for “ask what to do”
– do shell script “defaults write com.apple.digihub com.apple.digihub.music.cd.appeared -dict action 101”
– for “open in iTunes”
– get parameters from Filemaker Pro I need for this script
tell application “FileMaker Pro Advanced”
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
–to debug uncomment the following two lines
–set database_folder to “MacBook HD:Users:Kevin:Documents:allyn database stuff:”
–set toBurnSound to “KevinMiller8888.aiff”
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 Advanced"
set cell "ToBurnSound" of record 1 of table "Preferences" to "Sound file too Large"
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 Advanced"
if error_number is -1728 then
set cell "ToBurnSound" of record 1 of table "Preferences" to "File not Found"
else
set cell "ToBurnSound" of record 1 of table "Preferences" to error_message & return & "Error number " & error_number
end if
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 Advanced"
set cell "ToBurnSound" of record 1 of table "Preferences" to user_cancel
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
–check for blank CD
set BlankCD to checkdiscstatus()
if BlankCD is "blank" 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 external burn -audio -eject " & 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
else
set alerttext to "The following problem occured:" & "
" & BlankCD & "
" & “Please Find a blank CD and try again.”
tell me to display dialog alerttext buttons {“OK”} default button “OK” with icon caution
return BlankCD
end if
end Burn_the_CD
on checkdiscstatus()
–check if a disc drive is even present
set x to do shell script “drutil status”
if x is “” then
–no drive is connected
return “no disc Drive present”
else
set howlongtowait to 0
–repeat until user inserts disc or a certain time is reached
repeat while (x contains “No Media Inserted”)
delay 2
set howlongtowait to howlongtowait + 2
if howlongtowait > 25 then
–about 25 seconds
return “no CD inserted”
end if
– check again
set x to do shell script “drutil status”
end repeat
delay 2
if x contains "appendable, blank, overwritable" then
--The disc inserted is blank and writeable
return "blank"
else
-- The disc inserted is not writable
do shell script "diskutil eject disk1"
return "Not a Blank Disc"
end if
end if
end checkdiscstatus
Model: macbook pro
AppleScript: 2.6.1
Browser: Safari 537.77.4
Operating System: Mac OS X (10.8)