Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

realityisterror

macrumors 65816
Original poster
Aug 30, 2003
1,354
1
Snellville, GA
i like to log my ichats... but they are all dumped into one folder by default...
i want help from you wonderful people ;) with writing an applescript to use as a "folder action" that would sort the logs into folders by person and preferably remove the person's name from the beginning of the file name after it has been moved (because the file names are very long)

here's the format that the logs are saved in:
Bobby Smith on 2004-09-09 at 21.38.chat

i would want that put into a folder called Bobby Smith along with all other Bobby Smith logs..

thanks for the help,
reality
 
I think this is what you want. As items are added to the folder, it checks to see if the name contains " on " (meaning that it's in the iChat naming format). It then renames the file to the text after " on " (eg "2004-09-09 at 21.38.chat") and moves it to the folder named with the text before " on " (eg "Bobby Smith").

To set it up, as you're probably aware, copy the code below into Script Editor, save it as a script in /Library/Scripts/Folder Action Scripts, and then attach it to ~/Documents/iChats.

Limitations:
*If you have two chats with the same person in the same minute, the second one won't be moved into the folder, it will just be renamed.
*It won't move/rename files that are already there. To process them, move them out of the folder and then back in.

Let me know of any problems.

Code:
on adding folder items to thisFolder after receiving newItems
	set thisFolder to thisFolder as string
	set delim to AppleScript's text item delimiters
	set AppleScript's text item delimiters to {" on "}
	
	repeat with i from 1 to (count of newItems)
		set currItem to item i of newItems
		tell application "Finder"
			set itemName to name of currItem
			if ((count of text items of itemName) > 1) then --Otherwise non-standard name, do nothing
				set personName to first text item of itemName
				set newFileName to second text item of itemName
				set folderForFile to thisFolder & personName & ":"
				if not (exists folder folderForFile) then
					make new folder at alias thisFolder with properties {name:personName}
				end if
				set name of currItem to newFileName
				set currItem to file (thisFolder & newFileName)
				move currItem to folder folderForFile
			end if
		end tell
	end repeat
	set AppleScript's text item delimiters to delim
end adding folder items to
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.