Make files download to specified folders...

indigoflowAS

macrumors 6502
Original poster
Oct 31, 2005
268
0
Columbus, OH
I'm trying a new organization scheme, where I try to keep my desktop as bare as humanly possible. So I want files I download in Camino (my main browser) to go to specific folders...Example, .torrent files to move to a folder named "Torrents" and .pdfs to show up in its own "PDF" folder.

I dont believe you can tell Camino to do that, can a script be set to do that automatically as i casually download stuff from the web?...as in, maybe the file shows up on the desktop for a second, then it is moved to one of these folders OR the way that mail does it with rules.

Smart folders are ok, but they are not viewable in the finder column mode...which is strange to me.

Thanks for taking the time, peace.
 

emw

macrumors G4
Aug 2, 2004
11,177
0
I'm assuming you're downloading so many of these that using the "Save Link As..." option is too problematic?

I'm sure you could set up a watched folder script so that you have a single download folder that is watched and then the script moves files into appropriate final destination folders, but it would likely be fairly simplistic, based only on the extension of the file, as you've mentioned.

I would think that it would be more beneficial to sort files by content or purpose rather than file type, but that would require the manual save as step.
 

indigoflowAS

macrumors 6502
Original poster
Oct 31, 2005
268
0
Columbus, OH
sounds good, i'll look into the whole watched script, see how that plays out. much appreciated.:)

any more ideas are more than welcome.
 

jsw

Moderator emeritus
Mar 16, 2004
22,910
41
Andover, MA
What works for me is the following:
  • Set up a folder for downloads on your Desktop and call it, say, "Downloads".
  • Within "Downloads", set up a number of Smart Folders which are set to look only at content within that "Downloads" folder (which will also pick up subfolders).
  • In "Downloads", create another folder which holds processed downloads and call it, say, "Processed".
  • Make a script to move everything put in the "Downloads" folder to "Processed".
  • Make any subfolders within "Processed" that you want (if any) and set up rules to move files appropriately.

The reason you create the folder within the downloads folder is simply for ease of viewing - you don't end up with some Smart Folders sprinkled amidst a thousand downloaded files. Instead, all downloaded files are immediately moved farther down, but yet you still have a single main folder for downloads. Alternate way: just download files directly to that subfolder. I set up the script to move them from the Downloads folder (instead of just downloading them to the subfolder) so I can drag files downloaded elsewhere to my Downloads folder and they get handled without me needing to open it up.

The reason you use Smart Folders is that they allow you to categorize the same file in many different ways. Instead of having to pick one place to "put" it, Smart Folders let the same file "be" in many places. I love this.

The reason you'd use (possibly) subfolders beneath the "processed" folder is simply in case you want separate physical folders for different types of files (might make backup easier).
 

indigoflowAS

macrumors 6502
Original poster
Oct 31, 2005
268
0
Columbus, OH
brilliant,

well, now i guess i need to learn how to make simple scripts that tell files to move from one folder to the next (from "downloads" to "processed" in this case).

enlighten my naiveté. thanks.
 

indigoflowAS

macrumors 6502
Original poster
Oct 31, 2005
268
0
Columbus, OH
if anyone can point me in the direction of some applescripts learing/resource sites...that would be super. all it appears i need is a "move" script and the ability to change the definition of the file that is to be moved.

appreciated:)
 

jsw

Moderator emeritus
Mar 16, 2004
22,910
41
Andover, MA
Create the folders you want (for example, a Downloads folder on your desktop and a Processed folder within).

Open up Applications->AppleScript->Script Editor.

In the new window you should see (else File->New), type:
Code:
on adding folder items to this_folder after receiving added_items
	try
		tell application "Finder"
			repeat with eachItem in added_items
				move eachItem to folder "Macintosh HD:Users:[b][color=blue]macrumors[/color][/b]:[b][color=red]Desktop[/color][/b]:[b][color=red]Downloads[/color][/b]:[b][color=red]Processed[/color][/b]:"
			end repeat
		end tell
	end try
end adding folder items to
Except that you need to replace "macrumors:Desktop:Downloads:Processed" with your user name (blue) and the folder path (red) - assuming you don't just use the one I do. Note that the coloring is mine and is just for illustrative purposes.

Then do a File->Save to "/Library/Scripts/Folder Action Scripts" as whatever name you want (say, "DownloadMover").

Close the Script Editor.

Right or control click on the Downloads folder on your Desktop. Select "Enable Folder Actions" (if all you see is "Disable Folder Actions" they're already enabled).

Right/control click again on that Downloads folder and select "Attach a Folder Action".

Navigate to "DownloadMover" or whatever you called it and select it.

You should be golden.

You can duplicate this with subfolders within "Processed" (or whatever you call it) but you'll need more AppleScript than I can easily go into here, assuming I even know it. Google is your friend!
 

HexMonkey

Administrator
Staff member
Feb 5, 2004
2,161
432
New Zealand
To have your files automatically moved to subfolders based on their extensions, you can use this folder action script. Set it up the same way as jsw described earlier.

Code:
on adding folder items to this_folder after receiving added_items
    try
        tell application "Finder"
            repeat with anItem in added_items
                --Check the item's type, we don't move folders
                if (class of item anItem is not folder) then
                    --Get the file's extension
                    set extension to name extension of anItem
                    set hasExtension to true
                    if (extension is "") then
                        set extension to "No extension"
                        set hasExtension to false
                    end if
                    
                    --Get the destination folder or create it if necessary
                    set destinationFolder to (this_folder as string) & extension & ":" as string
                    if not (exists folder destinationFolder) then
                        make new folder at this_folder with properties {name:extension}
                    end if
                    
                    --Find a unique name for the file inside the new folder so that we don't replace existing files
                    set counter to 1
                    set oldName to name of anItem
                    set newName to oldName
                    set destinationLoc to destinationFolder & newName as string
                    repeat while exists item destinationLoc
                        if (not hasExtension) then
                            set newName to oldName & " " & (counter as string) as string
                        else
                            set newName to (characters 1 thru -((length of extension) + 2) of oldName) & " " & (counter as string) & "." & extension as string
                        end if
                        
                        set destinationLoc to destinationFolder & newName as string
                        set counter to counter + 1
                    end repeat
                    
                    --Move the item to the destination folder
                    set name of anItem to newName
                    move anItem to folder destinationFolder
                end if
            end repeat
        end tell
    end try
end adding folder items to
The script will try and move new files to a subfolder with the same name as their extensions, creating the subfolder if necessary. If a file doesn't have an extension it will be moved to a folder called "No extension". If a new file has the same name as an existing file in the subfolder it will be appropriately renamed by adding a number to its filename.
 

indigoflowAS

macrumors 6502
Original poster
Oct 31, 2005
268
0
Columbus, OH
zorg said:
Set it up in prefs. of the program.
only if it were that simple...

i cannot tell Camino to take downloaded .pdfs and move them to one folder...and tell Camino to take downloaded .zips and move them to a different folder

Thanks to Hex. Works like a charm, see if i can experiment some more w/ this as a template:)
 

chairguru22

macrumors 6502a
May 31, 2006
623
38
PA
emw said:
I'm assuming you're downloading so many of these that using the "Save Link As..." option is too problematic?
how do you use the "save link as..." feature and direct where a d/l should go? or is it just going to d/l to the desktop and i have to move it my self?
 

HexMonkey

Administrator
Staff member
Feb 5, 2004
2,161
432
New Zealand
chairguru22 said:
how do you use the "save link as..." feature and direct where a d/l should go? or is it just going to d/l to the desktop and i have to move it my self?
Right-click/control-click the link, then hold down the option key and choose "Save Linked File As..." or "Download Linked File As..." depending on the context (holding down option changes them from "Save Linked File to <folder>" and "Download Linked File" respectively).