I have a script that I am creating to take an “AIFF audio file” and add it to itunes. I wanted to be able to test for two things before continuing with the script.
one: does the file exist
two: is the file kind “AIFF audio file”
If the file doesn’t exist or the kind is not “AIFF audio file” I wanted to end the script.
What I have is as follows:
set this_file to "MacBook HD:Users:Kevin:Documents:allyn database stuff:savedaudio:Miller8632.aiff"
set pList to "AllynClientName"
set gwarn to 1
try
if (kind of (info for file this_file)) ≠"AIFF Audio File" then
set addenda to "The sound file is not the correct type to burn. Contact tech support or record a new voice note and try to burn a CD again."
set user_cancel to "wrong file type"
my alert_user_and_cancel(addenda, user_cancel, gwarn)
end if
on error
set addenda to "The sound file is corrupted or could not be found on your computer. Contact tech support or record a new voice note and try to burn a CD again."
set user_cancel to "no file found"
my alert_user_and_cancel(addenda, user_cancel, gwarn)
end try
--this is where the rest of the script is for burning a CD in iTunes. I do not want it to run if an error occurs
--above or the file is not of the kind "AIFF Audio File"
display dialog "here we are"
to alert_user_and_cancel(message, user_cancel, gwarn)
if gwarn = 1 then
display dialog message buttons {"I understand"} default button 1 with icon 0 giving up after 10
else
display dialog message buttons {"I understand"} default button 1 with icon 0
end if
end alert_user_and_cancel
I know I am missing something simple, but I can’t seem to figure it out
Please help
Kevin
Model: MacBook
Browser: Safari 419.3
Operating System: Mac OS X (10.4)
set this_file to "MacBook HD:Users:Kevin:Documents:allyn database stuff:savedaudio:Miller8632.aiff"
set pList to "AllynClientName"
set gwarn to 1
try
if (kind of (info for file this_file)) ≠"AIFF Audio File" then
set addenda to "The sound file is not the correct type to burn. Contact tech support or record a new voice note and try to burn a CD again."
set user_cancel to "wrong file type"
my alert_user_and_cancel(addenda, user_cancel, gwarn)
end if
on error number errNum
if errNum = -128 then error number -128 -- cancel
set addenda to "The sound file is corrupted or could not be found on your computer. Contact tech support or record a new voice note and try to burn a CD again."
set user_cancel to "no file found"
my alert_user_and_cancel(addenda, user_cancel, gwarn)
end try
--this is where the rest of the script is for burning a CD in iTunes. I do not want it to run if an error occurs
--above or the file is not of the kind "AIFF Audio File"
display dialog "here we are"
to alert_user_and_cancel(message, user_cancel, gwarn)
if gwarn = 1 then
display dialog message buttons {"I understand"} default button 1 cancel button 1 with icon 0 giving up after 10
else
display dialog message buttons {"I understand"} default button 1 cancel button 1 with icon 0
end if
end alert_user_and_cancel
set this_file to "MacBook HD:Users:Kevin:Documents:allyn database stuff:savedaudio:Miller8632.aiff"
set pList to "AllynClientName"
set gwarn to 1
try
set this_file to this_file as alias
on error
set addenda to "The sound file is corrupted or could not be found on your computer. Contact tech support or record a new voice note and try to burn a CD again."
set user_cancel to "no file found"
my alert_user_and_cancel(addenda, user_cancel, gwarn)
end try
if (name extension of (info for file this_file)) is not in {"aiff", "aif"} then
set addenda to "The sound file is not the correct type to burn. Contact tech support or record a new voice note and try to burn a CD again."
set user_cancel to "wrong file type"
my alert_user_and_cancel(addenda, user_cancel, gwarn)
end if
--this is where the rest of the script is for burning a CD in iTunes. I do not want it to run if an error occurs
--above or the file is not of the kind "AIFF Audio File"
display dialog "here we are"
to alert_user_and_cancel(message, user_cancel, gwarn)
if gwarn = 1 then
display dialog message buttons {"I understand"} default button 1 cancel button 1 with icon 0 giving up after 10
else
display dialog message buttons {"I understand"} default button 1 cancel button 1 with icon 0
end if
end alert_user_and_cancel
I modified it slightly by placing the code to burn the CD inside an if else end if and I only wanted to test for AIFF:
set this_file to “MacBook HD:Users:Kevin:Documents:allyn database stuff:savedaudio:KevinMiller8632.aiff”
set pList to “AllynClientName”
set gwarn to 0
try
set test_file to this_file as alias
on error
set addenda to “The sound file is corrupted or could not be found on your computer. Contact tech support or record a new voice note and try to burn a CD again.”
set user_cancel to “no file found”
my alert_user_and_cancel(addenda, user_cancel, gwarn)
end try
if (kind of (info for file this_file)) is “AIFF Audio File” then
–this is where the rest of the script is for burning a CD in iTunes. display dialog “here we are”
else
set addenda to “The sound file is not the correct type to burn. Contact tech support or record a new voice note and try to burn a CD again.”
set user_cancel to “wrong file type”
my alert_user_and_cancel(addenda, user_cancel, gwarn)
end if
to alert_user_and_cancel(message, user_cancel, gwarn)
if gwarn = 1 then
display dialog message buttons {“I understand”} default button 1 cancel button 1 with icon 0 giving up after 10
else
display dialog message buttons {“I understand”} default button 1 cancel button 1 with icon 0
end if
end alert_user_and_cancel