Hello
My first post here, MacScripter seems to be a very helpful and pleasant place! I hope to get more assistance than I did over at the Apple forums - they were useless! Anyways, down to business.
Quite simply, I want a ‘Sorting Bin’ on my Desktop, which will do various things with any files/folders dropped on it, such as:
- categorise different file types into respective folders (in sensible groupings, so PDFs and text files in ‘Documents’)
- also, to move certain specific types to other places, such as pictures to the Pictures folder of my home folder.
I also want to be able to set is a Folder Action, so it is activated upon receiving new files into the Sorting Bin.
I know this is demanding of me, especially as I’m such a noob, but I’m keen to learn and I’ve done as much searching as I can for similar ideas and solutions.
I’ve found the following script which does a lot of what I want (thanks to wayfarer_boy, at the following post: http://bbs.applescript.net/viewtopic.php?id=10365 )
property imageList : {"gif", "jpg", "psd", "tif", "pic", "pict", "jpeg"}
property textList : {"txt", "doc", "rtf", "clpt", "tab", "sql"}
property pdfList : {"pdf"}
property soundsList : {"wav", "mp3", "m4a", "aif", "aiff"}
property flashList : {"fla", "swf"}
property directorList : {"dir", "dcr"}
property macList : {"sit", "dmg"}
property pcList : {"exe", "zip"}
property freehandList : {"AGD6"}
property webList : {"htm", "php"}
property finalList : {"FCPF"}
property filemakerList : {"fp5"}
property afterList : {"aep"}
property movieList : {"mov", "avi", "mpg", "MooV", "MPEG", "3gp"}
property appList : {"appl"}
property typeList : {}
on open TheFolder
tell application "Finder"
(* set the TheFolder to the dropped folder name *)
set TheFolder to TheFolder as text
(* set FolderList to the dropped folder name - in case of multiple folders, list as list *)
set FolderList to {TheFolder}
(* start with first item on list of dropped items *)
(* and set TheFolder to the first dropped item *)
set TheFolder to item 1 of FolderList
set TheFolder to TheFolder as text
repeat
try
set TheType to {name, file type, creator type} of first file of folder TheFolder
set TheName to item 1 of TheType
set TheFileType to item 2 of TheType
set N to count of characters of TheName
if (N > 3) and character (N - 3) of TheName is "." then
set TheName to characters (N - 2) thru N of TheName
set TheName to TheName as text
end if
if ((imageList contains TheName) or (imageList contains TheFileType)) then
set TheFolderName to "Images"
else if ((textList contains TheName) or (textList contains TheFileType)) then
set TheFolderName to "Text files"
else if ((pdfList contains TheName) or (pdfList contains TheFileType)) then
set TheFolderName to "PDF files"
else if ((soundsList contains TheName) or (soundsList contains TheFileType)) then
set TheFolderName to "Sounds"
else if ((flashList contains TheName) or (flashList contains TheFileType)) then
set TheFolderName to "Flash files"
else if ((directorList contains TheName) or (directorList contains TheFileType)) then
set TheFolderName to "Director files"
else if ((macList contains TheName) or (macList contains TheFileType)) then
set TheFolderName to "Mac files"
else if ((pcList contains TheName) or (pcList contains TheFileType)) then
set TheFolderName to "PC files"
else if ((freehandList contains TheName) or (freehandList contains TheFileType)) then
set TheFolderName to "Freehand files"
else if ((webList contains TheName) or (webList contains TheFileType)) then
set TheFolderName to "Site files"
else if ((finalList contains TheName) or (finalList contains TheFileType)) then
set TheFolderName to "Final Cut files"
else if ((filemakerList contains TheName) or (filemakerList contains TheFileType)) then
set TheFolderName to "Filemaker files"
else if ((afterList contains TheName) or (afterList contains TheFileType)) then
set TheFolderName to "After Effect files"
else if ((movieList contains TheName) or (movieList contains TheFileType)) then
set TheFolderName to "Movies"
else if ((appList contains TheName) or (appList contains TheFileType)) then
set TheFolderName to "Application files"
else
set TheFolderName to "Unknown"
end if
try
move file 1 of folder TheFolder to folder TheFolderName of folder TheFolder
on error
make new folder at folder TheFolder with properties {name:TheFolderName}
end try
on error
exit repeat
end try
end repeat
end tell
end open
Now, thanks to Applescript’s pseudo-english, this makes some sense to me. I understand how it organises each type into ‘groups’ so it can treat them separately. This enables me to fiddle with the groups and add extra types. So far, so good. I understand how to rename the respective folders also.
I’m keen to learn: if any experts fancy annotating this script with a few one-liners explaining what various bits do I’d be very grateful - this would enable me to learn by fiddling.
Things I want to add to this script -
- I want to add the ‘activate on receiving a file’ Folder actions trigger to it, and am unsure how.
- If possible, I want to be able to move certain groups elsewhere rather than into their folders-by-type, such as images to my Pictures folder in my Home folder. If anyone could add this tiny functionality and indicate which bits to fiddle with to customise it, I’d be absolutely over the moon and very grateful.
- Does the script need adjusting so that it would wait until larger files have finished copying before activating? Perhaps a strategically placed pause?
Cheers guys, thanks so much for helping.
Model: iMac G5 20"
Browser: Safari 419.3
Operating System: Mac OS X (10.4)