Hi all,
I am new at AS and only scratching the surface yet.
I’m trying to make a FolderAction that can ZIP an incoming folder, and then ftp it.
So far I got a working ZIP-action;
on adding folder items to this_folder after receiving these_items
tell application “Finder”
if not (exists folder “Done” of this_folder) then
make new folder at this_folder with properties {name:“Done”}
end if
set the destination_folder to folder “Done” of this_folder as alias
set the destination_directory to POSIX path of the destination_folder
end tell
repeat with i from 1 to number of items in these_items
set this_item to item i of these_items
set the item_info to info for this_item
if this_item is not the destination_folder and the name extension of the item_info is not in {“zip”, “sit”} then
set the item_path to the quoted form of the POSIX path of this_item
set the destination_path to the quoted form of (destination_directory & (name of the item_info) & “.zip”)
do shell script ("/usr/bin/ditto -c -k -rsrc --keepParent " & item_path & " " & destination_path)
end if
end repeat
end adding folder items to
This one works fine.
I also have a simple ftp-action that works fine;
on adding folder items to this_folder after receiving added_items
tell application “URL Access Scripting”
try
repeat with i from 1 to number of items in added_items
set theFile to item i of added_items
upload theFile to “ftp://user:pass@xxx.xxx.xxx.xxx/” replacing yes without binhexing
end repeat
end try
end tell
end adding folder items to
Is there a way to combine those “ in one Folder Action? Like Zipping the file/folder, send the .ZIP on FTP, and then move the zip to a “Done” folder?
You’re pretty far along for a newbee. If you have OSX 10.4 installed, check out Automator, which simplifies workflows like yours.
You’ll need to add some more error catching…
on adding folder items to this_folder after receiving these_items
tell application “Finder”
if not (exists folder “Done” of this_folder) then
make new folder at this_folder with properties {name:“Done”}
end if
set the destination_folder to folder “Done” of this_folder as alias
set the destination_directory to POSIX path of the destination_folder
end tell
repeat with i from 1 to number of items in these_items
set this_item to item i of these_items
set the item_info to info for this_item
if this_item is not the destination_folder and the name extension of the item_info is not in {“zip”, “sit”} then
set the item_path to the quoted form of the POSIX path of this_item
set the destination_path to the quoted form of (destination_directory & (name of the item_info) & “.zip”)
do shell script ("/usr/bin/ditto -c -k -rsrc --keepParent " & item_path & " " & destination_path)
--
-- You could just move the ftp part into your zip script...
--
tell application "URL Access Scripting"
try
set theFile to (destination_folder & (name of the item_info) & ".zip")
upload theFile to "ftp://user:pass@xxx.xxx.xxx.xxx/" replacing yes without binhexing
end try
end tell
-- Tell finder to move the zip file
tell application "Finder"
move theFile to "Macintosh HD:Users:XXX:" with replacing
end tell
end if
end repeat
Except from a minor typo (destination_folder = destination_directory) this works fine!
Maybe, in the last part, there should also be a "make new folder at this_folder with properties {name:“Sendt_originals”}, but that might cause a loop? I don’t know.
I have tried Automator, but I want this to be a “HotFolder” on a LAN 10.3 Server for several users, and the Server would not run the App.
Here’s the final script without typo “ if anyone else would need it:
on adding folder items to this_folder after receiving these_items
tell application “Finder”
if not (exists folder “Done” of this_folder) then
make new folder at this_folder with properties {name:“Done”}
end if
set the destination_folder to folder “Done” of this_folder as alias
set the destination_directory to POSIX path of the destination_folder
end tell
repeat with i from 1 to number of items in these_items
set this_item to item i of these_items
set the item_info to info for this_item
if this_item is not the destination_folder and the name extension of the item_info is not in {“zip”, “sit”} then
set the item_path to the quoted form of the POSIX path of this_item
set the destination_path to the quoted form of (destination_directory & (name of the item_info) & “.zip”)
do shell script ("/usr/bin/ditto -c -k -rsrc --keepParent " & item_path & " " & destination_path)
-- Moves the ZIP file to FTP
tell application "URL Access Scripting"
try
set the_file to (destination_directory & (name of the item_info) & ".zip")
upload the_file to "ftp://user:pass@xx.xxx.xxx.xxx/" replacing yes without binhexing
end try
end tell
-- Tell finder to move the original file/folder
tell application "Finder"
move this_item to "Macintosh HD:Users:You:XXX" with replacing
end tell
end if
end repeat