I am a total newbie to applescript, I’ve browsed through some forums and tried to make a script that uploads some files to a ftp server. The problem is I always get an error when it selects files from a folder.
The code is
tell application "Cyberduck"
set dreamBrowser to (make new browser)
set dreamFolder to "mi2:Pictures:Shoot:toSubmit:dream"
tell dreamBrowser
tell application "Finder" to set dFiles to (every file of dreamFolder whose name extension is "jpg")
repeat with dFile in dFiles
alert(name of dFile)
end repeat
end tell
tell dreamBrowser to close
end tell
While running I always get the error message:
Can’t get every file of “mi2:Pictures:ShutterStock:toSubmit:dream”.
Can anyone help me please.
note1: mi2 is the secondary partition on my mac
note2: the listing of the mi2:Pictures:Shoot:toSubmit:dream folder is:
.DS_Store
IMG_6073.IMG
IMG_6074.IMG
note3: the IMG_.IMG files are no real files, but the aliases
note4: I plan to select the IMG_.jpg files.
Thanks Stefan,
that seem to have been the problems… now I can select the right files. However I have the following problem with the Cyberduck program. This is an example application from Cyberduck that uploads files:
on adding folder items to this_folder after receiving added_items
set theServer to "example.net"
set theUser to "username"
set theProtocol to "ftp"
set theUploadFolder to "upload"
set the item_count to the number of items in the added_items
if the item_count is greater than 0 then
with timeout of 300 seconds
tell application "Cyberduck"
set theBrowser to (make new browser)
tell (theBrowser)
set encoding to "UTF-8"
connect to theServer with protocol theProtocol as user theUser with initial folder theUploadFolder
repeat with theFile in added_items
upload item theFile
end repeat
disconnect
end tell
end tell
end timeout
end if
end adding folder items to
now this is the source of my application
set dreamFolder to "mi2:Pictures:Shoot:toSubmit:dream:"
tell application "Finder" to set dFiles to (get every alias file of folder dreamFolder whose name extension is "jpg")
--if we have files
if (number of items in dFiles is greater than 0) then
with timeout of 300 seconds
tell application "Cyberduck"
set dreamBrowser to (make new browser)
tell (dreamBrowser)
connect to bookmark "dream"
repeat with dFile in dFiles
tell application "Finder" to set oFile to original item of dFile
upload item oFile
end repeat
disconnect
close
end tell
end tell
end timeout
end if
The problem: the line
upload item oFile
throws the exception:
Can’t make «class docf» “IMG_6073.JPG” of «class cfol» “toSubmit” of…«class cdis» “mi2” of application “Finder” into the expected type.
But I did the same as in the example provided by Cyberduck, didn’t I? Can someone please help?
The original example uses an alias (the Applescript class, not an alias file), your script uses a file specifier
maybe this does it (I don’t have Cyberduck)
tell application "Finder" to set oFile to original item of dFile as alias