Organize iChat archive files by sender

Sep 10, '04 09:32:00AM

Contributed by: jaysoffian

This isn't much of a hint, but what the heck, if someone else had posted it to macosxhints.com, it would've saved me five minutes. So here ya go.

I log all of my iChats, and recently noticed that my Documents -> iChats directory was out of control. I figured it would be a good thing to file all the chats into a directory (folder) for each person I chatted with.

Read the rest of the hint for a simple Python script to do just that...

Using your favorite Terminal or GUI text editor, create this script:

#!/usr/bin/python

import sys
import os, os.path
import re

ichats_dir = os.path.join(os.getenv("HOME"), "Documents/iChats")

patterns = map(re.compile,
   (
        r" on \d{4}-\d{2}-\d{2} at \d{2}\.\d{2}\.chat$",
        r" on \d{4}-\d{2}-\d{2} at \d{2}\.\d{2} #\d+\.chat$",
        r" #\d+\.chat$",
        r"\.chat$",
    )
)

for chat in os.listdir(ichats_dir):
    aim = None
    for pattern in patterns:
        if pattern.search(chat):
            aim = pattern.sub("", chat)
            break
    if aim is None: continue
    aim_dir = os.path.join(ichats_dir, aim)
    if not os.path.isdir(aim_dir): os.mkdir(aim_dir)
    src = os.path.join(ichats_dir, chat)
    dst = os.path.join(ichats_dir, aim_dir, chat)
    print "%s -> %s/%s" % (chat, aim_dir, chat)
    os.rename(src, dst)
Does the job for me.

[robg adds: Simple script for 'jaysoffian,' perhaps! I tested this, and it worked perfectly -- create the script in the Terminal, make it executable (chmod 755 script_name), and then run it (./script_name). On my machine, it organized 1,600+ chat transcripts in about 30 seconds or so. That's the good news.

The bad news is if you, like me, rely on Logorrhea to search and browse your log files, this new organization structure breaks it completely. I'm going to see if the author of Logorrhea can update the app to search sub-folders as well; then I could have the best of both worlds. And hopefully Apple will add username organization to the log file in the future; it just makes more sense.]

Comments (3)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20040909161117627