|
|||||||
![]() |
|
|
Thread Tools |
Rating:
|
Display Modes |
|
|
#1 |
|
Prospect
Join Date: May 2003
Posts: 26
|
Folder Actions - Automatically sorting Safari's downloads folder?
Hi all,
I'm wondering if someone could help me with a folder action... I'd like to automate sorting of files that get downloaded to Safari's downloads folder (to keep it tidy). For example, if I download an Image, that image should be moved to a folder I specify. I guess the simplest thing to do is to look at the file extension and sort it based on that. Could someone quickly show us a piece of code that moves a file based on file extension? Thanks!! Mike |
|
|
|
|
|
#2 |
|
Major Leaguer
Join Date: Aug 2003
Posts: 429
|
This might work.
Code:
on adding folder items to this_folder after receiving added_items repeat with item_ in added_items tell application "Finder" if name extension of item_ is "jpg" then try -- in case of name conflict in destination move item_ to folder "path:to:images:" end try end if if name extension of item_ is "mp3" then try move item_ to folder "path:to:music:" end try end if end tell end repeat end adding folder items to |
|
|
|
|
|
#3 |
|
Prospect
Join Date: Nov 2004
Posts: 21
|
completeish solution
Just what I needed for my messy downloads folder, brilliant, I love applescript.
Combined robJ's solution with some Library's Folder Actions script and came up with this. I'm using a lists for file extensions and there's also a handler which renames the file if a dublicate exists. Maybe not the tidiest piece of script but does what it's told and it should be easy enough to extend. ::: Code:
(*This folder action script is designed to keep your downloads folder organised *) property image_extension_list : {"tif", "tiff", "gif", "png", "pict", "pct", "jpg"} property media_extension_list : {"mp3", "avi", "mov", "mpg"} property archive_extension_list : {"zip", "sit", "dmg", "tar", "hqx", "toast"} property image_foldername : "images" property media_foldername : "media" property archive_foldername : "archives" on adding folder items to this_folder after receiving added_items repeat with this_item in added_items tell application "Finder" if (the name extension of the this_item is in the image_extension_list) then my makeamove(this_item, this_folder, image_foldername) end if if (the name extension of the this_item is in the media_extension_list) then my makeamove(this_item, this_folder, media_foldername) end if if (the name extension of the this_item is in the archive_extension_list) then my makeamove(this_item, this_folder, archive_foldername) end if end tell end repeat end adding folder items to on makeamove(this_item, root_folder, target_foldername) tell application "Finder" if not (exists folder target_foldername of root_folder) then make new folder at root_folder with properties {name:target_foldername} end if set the target_folder to folder target_foldername of root_folder my resolve_conflicts(this_item, root_folder, target_folder) move file this_item to the target_folder end tell end makeamove on resolve_conflicts(this_item, root_folder, target_folder) --renames the item if dublicate exists in target folder tell application "Finder" set file_extension to the name extension of this_item set the file_name to the name of this_item if the file_extension is "" then set the trimmed_name to the file_name else set the trimmed_name to text 1 thru -((length of file_extension) + 2) of the file_name end if if (exists document file file_name of target_folder) then set the name_increment to 1 repeat set the new_name to (the trimmed_name & "_" & (name_increment as string) & "." & file_extension) as string if not (exists document file new_name of the target_folder) then set the name of document file file_name of folder root_folder to the new_name exit repeat else set the name_increment to the name_increment + 1 end if end repeat end if end tell return the file_name end resolve_conflicts Last edited by helloworld; 11-10-2004 at 05:43 AM. |
|
|
|
|
|
#4 |
|
Prospect
Join Date: May 2003
Posts: 26
|
Thanks guys! Both of the scripts work really well! Awesome stuff
|
|
|
|
|
|
#5 |
|
Triple-A Player
Join Date: Oct 2004
Posts: 70
|
You don't even need a script. Go to the downloads folder, hit command-J, choose "This folder only," and choose "Keep arranged by " and then select your sorting criteria.
__________________
Want Gmail? PM me! |
|
|
|
|
|
#6 | |||||||||||||||||||||||
|
Prospect
Join Date: May 2003
Posts: 26
|
I don't think you understand what we're talking about. Re-read this thread. We're talking about moving files. |
|||||||||||||||||||||||
|
|
|
|
|
#7 | |||||||||||||||||||||||
|
Prospect
Join Date: Jun 2005
Posts: 43
|
I think what Jacob is suggesting is that the needs that the original poster is looking to fulfill might be fulfilled without having to move files at all. |
|||||||||||||||||||||||
|
|
|
|
|
#8 |
|
Registered User
Join Date: Mar 2006
Posts: 1
|
Hiya, very useful script,
I've modified it to sort .torrent files (see below) but how do I get it to open a specific filetype when all this is done. Ie open the torrent file so downloading torrents becomes a one click process. Ideally it would open the file after it has been moved/renamed so as not to confuse the torrent app. I had a go but I haven't tried applescript in such a long time I'm a little bit unsure. Thanks P.S added rar to the archives extension list. Code:
(*This folder action script is designed to keep your downloads folder organised *) property image_extension_list : {"tif", "tiff", "gif", "png", "pict", "pct", "jpg"} property media_extension_list : {"mp3", "avi", "mov", "mpg"} property archive_extension_list : {"zip", "sit", "dmg", "tar", "hqx", "toast", "rar"} property torrent_extension_list : {"torrent"} property image_foldername : "images" property media_foldername : "media" property archive_foldername : "archives" property torrent_foldername : "torrents" on adding folder items to this_folder after receiving added_items repeat with this_item in added_items tell application "Finder" if (the name extension of the this_item is in the image_extension_list) then my makeamove(this_item, this_folder, image_foldername) end if if (the name extension of the this_item is in the media_extension_list) then my makeamove(this_item, this_folder, media_foldername) end if if (the name extension of the this_item is in the archive_extension_list) then my makeamove(this_item, this_folder, archive_foldername) end if if (the name extension of the this_item is in the torrent_extension_list) then my makeamove(this_item, this_folder, torrent_foldername) end if end tell end repeat end adding folder items to on makeamove(this_item, root_folder, target_foldername) tell application "Finder" if not (exists folder target_foldername of root_folder) then make new folder at root_folder with properties {name:target_foldername} end if set the target_folder to folder target_foldername of root_folder my resolve_conflicts(this_item, root_folder, target_folder) move file this_item to the target_folder end tell end makeamove on resolve_conflicts(this_item, root_folder, target_folder) --renames the item if dublicate exists in target folder tell application "Finder" set file_extension to the name extension of this_item set the file_name to the name of this_item if the file_extension is "" then set the trimmed_name to the file_name else set the trimmed_name to text 1 thru -((length of file_extension) + 2) of the file_name end if if (exists document file file_name of target_folder) then set the name_increment to 1 repeat set the new_name to (the trimmed_name & "_" & (name_increment as string) & "." & file_extension) as string if not (exists document file new_name of the target_folder) then set the name of document file file_name of folder root_folder to the new_name exit repeat else set the name_increment to the name_increment + 1 end if end repeat end if end tell return the file_name end resolve_conflicts |
|
|
|
|
|
#9 |
|
Major Leaguer
Join Date: Jul 2005
Posts: 364
|
Not sure if anyone is still watching this thread, but in case someone is, check out a program called Hazel - www.noodlesoft.com
It does everything mentioned above, and a whole lot more... |
|
|
|
![]() |
|
|