- bonis
- Medlem ●
- Göteborg
- 2010-09-10 21:48
Har försökt hitta ett Folder actions script som sorterar hämtade filer mappen. Hittade denna kod, som jag sparade som en scpt fil gick sedan in under inställningar för mappkommandon och ställde in hämtade filer mappen och valde mitt script. Det fungerar dock inte, så har jag missat något i koden eller i de övriga förfarandet ?
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 pdf_extension_list : {"pdf"}
property image_foldername : "images"
property media_foldername : "media"
property archive_foldername : "archives"
property torrent_foldername : "torrents"
property pdf_foldername : "pdf"
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
if (the name extension of the this_item is in the pdf_extension_list) then
my makeamove(this_item, this_folder, pdf_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