Howdy, I’m on the search for a folder action or scipt that will, when i download an image to the desktop, move this new image to a folder called “Various” in the pictures directory of my home folder. So you know, my hard drive is still called ‘Macintosh HD’ and my user name is ‘shanebryant’, if that helps, and everything else is pretty standard as i’m using a new ibook and am a new mac user… thank you ahead of time!!! I’m so glad there are forums out there like this with people that like to help!!!
There are a number of caveats to clarify before implementing such a script.
First, you want to apply the folder action to the desktop, right?
While I’ve never done that, I don’t see a huge problem applying a folder action to the desktop, it’s just a little unusual. Is there a reason why you’re downloading here rather than to a specific downloads folder?
Secondly, you say you want to move all image files… That’s OK, but you need to clarify what you consider an image file. JPG? GIF? PDF? TIF? BMP?
You see, your script will need to explicitly check the file type otherwise you’ll find all files on the desktop getting moved to your pictures folder, which isn’t what you want.
Given those, you should be able to take the following script as a starting point (untested):
property fileTypes : {"jpg", "gif", "tif"} -- adjust as necessary
property folderName : "Various"
on adding folder items to theFolder after receiving theAddedItems
tell application "Finder"
-- 'path to pictures folder' finds your 'Pictures' folder regardless of your username, disk name, etc.
set dest_Dir to (path to pictures folder from user domain) & folderName as string
-- check that the folder exists
if not (exists folder dest_Dir) then
-- if it's not there, create it
set dest_Dir to make new folder at (path to pictures folder from user domain) with properties {name:folderName}
end if
-- now iterate through the files added to the folder
repeat with eachFile in theAddedItems
try
if name extension of eachFile is in fileTypes then -- does the file match?
move eachFile to folder dest_Dir
end if
end try
end repeat
end tell
end adding folder items to
so i just take that and past it into “Script Editor” and then save it as .scpt and then run it? Script Editor stops and says "Expected “, " but found identifier.” Sorry, but, huh?
Copy and Paste the following code into a script and save it into your Folder Action Scripts folder (in Example Scripts of your Applescript folder). You will then want to view your Home Folder, select the “Desktop” and enable Finder Action Scripts. Attach the saved script to your Desktop Folder and you should be okay.
I normally name the script appropriately when I save it (ie: Add- Process Various Images)
property fileTypes : {"jpg", "gif", "tif"}
property folderName : {"Various"}
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 {}
--Find the Picture Folder and Create it if necessary
set dest_Dir to (path to pictures folder from user domain) & folderName as string
if not (exists folder dest_Dir) then
set dest_Dir to make new folder at (path to pictures folder from user domain) with properties {name:folderName}
end if
repeat with i from 1 to the count of fileTypes
copy item i of the fileTypes to {file_type}
set selected_files to {}
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 dest_Dir
else
-- Do Nothing
end if
end repeat
end tell
end try
end adding folder items to