Organize old iChat archive folders for use in 10.5

A few years back, we ran this hint, which used a Python script to organize archived iChats into subfolders based on the name of the iChat buddy. The script was necessary because, at the time, Apple simply dumped all archived iChats into the top-level of the iChats folder in the user’s Documents folder. In my case, I had literally thousands of files in that folder, making it very hard to navigate and find the one I was after. I ran the script a few times to clean things up, but over time, my folder became a mix of organized and unorganized chat archives.

The years passed, and along came OS X 10.5. Amongst the 300 other new features, iChat archives are now sorted into dated subfolders in the iChats folder. This makes for a cleaner folder, though I would have preferred to see the chats organized by the buddy’s name, not the date.

But it also caused an issue for me—I did a clean install of 10.5, so I had my previous iChats folder on my 10.4 partition with its mix of thousands of sorted-by-name and unsorted archives. I also had the now-organized iChats folder in 10.5. While Spotlight doesn’t really care where files are when I ask it to search out the tidbits of knowledge hidden in my iChat archives, I wanted everything in one cleaned-up folder—mainly for aesthetic reasons, but also because I wanted to zero out the 10.4 partition for other uses. However, given the size of the archive, arranging it in the new 10.5-style dated folders would be a herculean task.

Normally in the course of a hint, this is where I would offer a solution, and explain in detail how it works. Sometimes, however, the solution involves something that’s beyond my ability to fully explain…and that’s the case with today’s hint. The solution is a Perl script that magically sorts an iChats folder into a series of date-stamped subfolders—it will even move iChat archives that were previously arranged into named subfolders. My skills with Perl are rudimentary at best, which is why not much of a ‘how this works’ explanation comes with today’s hint. (The script was created by a reader on the macosxhints.com site.)

Since the code is long, I’ve placed it on its own page for ease of copying and pasting. If you haven’t already, copy the text (select it all, then press Command-C) on that page, then launch Terminal. In Terminal, type nano movechats to open the nano text editor. Now press Command-V to paste the copied text into the text editor. At this point, if you keep your iChats folder in its default location, you’re done with the editing—skip down to the section on saving the script. If, however, you don’t keep your iChat logs in your user’s Documents folder—or as in my case, you’re running the program on a folder from 10.4—you’ll also need to edit this line of the script:

open(FIND, "find '$ENV{HOME}/Documents/iChats' -name...

Replace $ENV{HOME}/Documents/iChats with the full path to the location of your iChats (or whatever you called it) folder. For instance, if I had my iChats stored on another volume, that line would look something like this—note the backslashes before any spaces in the path:

open(FIND, "find '/Volumes/10.4\ system/iChat\ Archives' -name...

The script will then run on that folder, and not the default folder.

Saving the script: Once you’re done editing, press Control-X (to exit the editor). When you press Control-X, nano will ask if you want to save changes; press Y, then press Enter to confirm the filename. Your script has now been saved in your user’s home directory.

To use the script, though, it needs to be executable. To make it so, type chmod +x movechats and press Enter. Before using the script, I recommend backing up your iChats folder—just in case something goes horribly wrong. In the Finder, hold down the Option key and drag your user’s Documents -> iChats folder to another location—holding Option will force the system to make a copy.

Once that’s done, switch back to Terminal, and type ./movechats and press Enter—don’t worry, nothing is actually going to happen yet. Instead, you should see output like this:

image

When you run the script in its default form, it will show you what it’s going to do, but not actually do it. You’ll see one line of output (though it will probably wrap to two lines, as above, unless you have a very wide Terminal window) for each chat archive the script is going to move, as well as entries for each directory it will create (mkdir...). When the script’s done, give this output a once-over to make sure everything looks right.

Once you’re sure everything looks right, edit your script again with nano movechats. On the third line of the file, my $PREVIEW = 1;, change the 1 to a 0. As noted by the comment on this line, setting this value to zero puts the script in operating, not preview mode. Press Control-X, Y, and Enter again to save your changes. Finally, run the script again (./movechats), and then check your iChats folder when the script is done. You should find a nicely organized folder.

If you used the script on an old iChats archive folder, you can then drag its contents into your 10.5 iChats folder to wind up with one merged folder—just make sure you don’t have any overlapping dates between the two folders. If you do, you’ll need to move those folders’ contents by hand, so you don’t overwrite the new archive’s entries for that date with the entries from the old archive.

Since this is a one-time-use script (chats in 10.5 will automatically be correctly filed), after you’ve run it, you can delete the script (or move it to a storage folder for possible use in the future).

  
Shop Tech Products at Amazon