I’m trying to set up a folder action that will move newly downloaded files from my downloads folder to a specific folder for a specific file type. Here is what works:
[color=blue]on adding folder items to this_folder after receiving added_items
tell application "Finder"
move added_items to folder "Music:Recent Downloads" of disk "Marvin"
end tell
end adding folder items to[/color]
Here is what doesn’t work:
[color=red]property extension_list : {“mp3”}
on adding folder items to this_folder after receiving added_items
if the file_extension is "" then
tell application "Finder"
move added_items to folder "Music:Recent Downloads" of disk "Marvin"
end tell
end if
end adding folder items to[/color]
I’ve been digging through all kinds of scripts for examples and from what I can tell this should work. Any help would be appreciated. Thanks,
Your script doesn’t work for so many reasons. First, “added_items”, as the name suggests, is a list, and lists don’t have extensions. Items of a list can have extensions. The term “file_extension” is a variable and it isn’t defined anywhere in your script. You need to loop through the items in the added_items list, get their extensions, and then file them. Take a look at this thread for the basis of an auto-sorting folder action based on extension.
Since the script is attached to your downloads folder, you’ll also need to be concerned with allowing downloads to complete before proceeding to move the files. Otherwise, the folder action might attempt to operate on incomplete files.
on adding folder items to this_folder after receiving added_items
try
tell application "Finder"
set the folder_name to the name of this_folder
set file_type to "mp3"
set selected_files to (every file of this_folder whose name extension contains file_type)
if (count of selected_files) >= 1 then
move (every file of this_folder whose name extension contains file_type) to folder "Music:Recent Downloads" of disk "Marvin"
else
-- Do Nothing
end if
end tell
end try
end adding folder items to