Hello,
I cannot seem to get a handle on how to coerce data! This time, I am trying to make a droplet for kids to drop mp3 files onto. It is very important that the names of these files are correct, so I put in an if/then to make sure the file names are correct. The relevant part of the script is below.
QUESTION #1
How do I get the name of the file(s) being turned in? In the event that they turn in an incorrectly named file, I want to be able to notify them with something like “Hey, the file FILENAME is named wrong…go back and fix it.” Testing this script, I turned in a file called “puzzle.jpg” from my desktop. This is not an approved file name, so the script should tell me this and exit. Instead, I get the error message “Can’t make name of alias (item 1 of {alias “Hard_Drive:Users:huber:Desktop:PUZZLE.jpg”}) of application “Finder” into type string.”
Can you see what I am doing wrong? I have tried other language besides “set CurrentFileName to name of alias (CurrentFile) as text,” but it has failed, too.
Thank you,
-Dave
--turn in each item
repeat with CurrentFile in draggedItems
--get the current file name
tell application "Finder" to ¬
set CurrentFileName to name of alias (CurrentFile) as text
--check if it is one of the approved names. If not, display error.
if (CurrentFileName = "Atlantis.mp3" or ¬
CurrentFileName = "Bonus.mp3" or ¬
CurrentFileName = "China.mp3" or ¬
CurrentFileName = "Completion.mp3" or ¬
CurrentFileName = "Crete.mp3" or ¬
CurrentFileName = "Night.mp3" or ¬
CurrentFileName = "Theme.mp3") then
tell application "Finder"
duplicate CurrentFile to DropBox replacing yes
end tell
else
tell application "SystemUIServer"
activate
display dialog "Sorry, the song '" & CurrentFileName & "' is named wrong. Go back and fix it." buttons {"Oops"} default button 1 giving up after 10
end tell
end if
end repeat