I am new to apple scripts. I have written a simple script at the moment to move a file from folder A to folder B on the Desktop.
tell application “Finder”
move every file of folder “Macintosh HD:User:Mac1:Desktop:Folder A” to folder “Macintosh HD:User:Mac1:Desktop:Folder B”
end tell
This works fine if I run it manually. But what I can’t get to work is using it as a folder action.
I have tried
on adding folder_items to this_folder after recieving them
tell application “Finder”
move every file of folder “Macintosh HD:User:Mac1:Desktop:Folder A” to folder “Macintosh HD:User:Mac1:Desktop:Folder B”
end tell
My aim is to have a script which will move file to a network drive but am just starting small at the moment.
Hope someone can shed some light on this as my head is blown now.
Folder actions respond to changes in folder contents, and that change is to be found in your word “them” which is a list of what was added so you move the files found in “them”. If you move a file from one volume (or partition) to another, the Finder will not “move” it, it “duplicates” it leaving the original where it found it (in case the transfer gets botched). If you want to move to a server, you duplicate to the server and then delete the file from the folder (it will end up in the trash if the Finder does it).
Specific problems with yours:
recieving should be receiving.
folder_items should be two words: folder items
The general structure is:
on adding folder items to this_folder after receiving added_items
set drive_name to "my_drive's_name"
tell application "Finder"
if drive_name is in (name of disks) then
duplicate file "Main_Drive:Users:username:Documents:folder:file" to folder "my_drive's_name:folder:" with replacing
say "file copied successfully"
eject disk drive_name
say "Transfer Complete"
end if
end tell
end adding folder items to