I have a droplet that uses an ftp subroutine to upload files to a server. The only files that are allowed are jpg, but I also have users who sometimes dump hi-res tiff, pdf and eps files.
Here’s the script (minus the subroutine and pertinent information)
on open input_items
activate
-- CHANGE THESE TO REFLECT YOUR SETTINGS
-- Include trailing slashes!
-- Leaving the URLprefix empty will make it so
-- nothing gets copied to your clipboard.
set ftpSite to "ftp://"
set ftpUser to ""
set ftpPass to ""
set URLprefix to ""
-- DON'T CHANGE ANYTHING BELOW HERE
repeat with i from 1 to number of items of input_items
set this_item to item i of input_items
set done to simpleFtpUpload(ftpSite, this_item, ftpUser, ftpPass)
tell application "Finder"
set item_name to the name of this_item
if URLprefix is not "" then
set the clipboard to URLprefix & item_name
end if
end tell
if done > 1 then
display dialog item_name & " has been uploaded." buttons {"OK"} default button 1 giving up after 5
end if
end repeat
return input_items
end open
All I want to do is if they drop an illegal file on the droplet pop up a dialog box chastising them (I know how to generate the dialog box, just don’t know how to filter the extensions in this setting) and gracefully exit the script.
exiting the script isn’t a good idea, the script can just filter and skip the file(s)
try this
.
repeat with i from 1 to number of items of input_items
set {name:item_name, name extension:Ex} to info for (item i of input_items)
if Ex is in {"jpg", "jpeg"} then
set done to simpleFtpUpload(ftpSite, this_item, ftpUser, ftpPass)
if URLprefix is not "" then
set the clipboard to URLprefix & item_name
end if
if done > 1 then
display dialog item_name & " has been uploaded." buttons {"OK"} default button 1 giving up after 5
end if
end if
end repeat
.
Thanks so much for the help. What you wrote worked almost perfectly.
I had to add the line
set this_item to item i of input_items
because the subroutine needed to have input_items passed to it and the script you wrote only took care of tossing out the files that weren’t jpg.
You guys (and gals) are a great resource.
Thanks again, and in case it might help, I have included the script as I am using it.
repeat with i from 1 to number of items of input_items
set {name:item_name, name extension:Ex} to info for (item i of input_items)
set this_item to item i of input_items
if Ex is in {"jpg", "jpeg"} then
set done to simpleFtpUpload(ftpSite, this_item, ftpUser, ftpPass)
if URLprefix is not "" then
set the clipboard to URLprefix & item_name
end if
if done > 1 then
display dialog item_name & " has been uploaded." buttons {"OK"} default button 1 giving up after 5
end if
else
display dialog item_name & " is not a jpg file and cannot be uploaded." buttons {"OK"} default button 1 giving up after 5
end if
end repeat
return input_items
Hi, Thanks for this script, but I am trying to use it formyself and am getting an error of "script doesn’t understand the simpleFtpUpload message.
What am I doing wrong?