TheGlide\’s blog

Ramblings, ramblings, ramblings…

Mac: dealing with Finder (and iPhoto) comments

leave a comment »

I’ve been using Mac OSX for less than a year and only now I’ve started playing with metadata. I’ve accumulated quite a number of PDF documents and I have lots of photos on my hard drive and to me the most natural thing seemed to add comments (actually tags, using the trick to prepend a “&” to each tag for ease of searching in Spotlight) either through the Finder “Get Info” window or through iPhoto’s interface.

The problem is that I often use the Terminal to do a variety of tasks and a lot of the commands that I use on a daily basis do not play well at all with Finder comments: for example if you use cp or mv to move files around, the affected files will not keep their Comment entry. This is because the metadata is not kept with the file (possibly using the extended attributes) but instead is stored in the .DS_Store file located in the parent directory of any given file. Neither rdiff-backup nor rsync (which I often use to transfer files to a Linux server) play well with metadata and you risk that your backup does not properly keep the Finder (or iPhoto) Comment. If instead you move files around with Finder (or use other backup solutions like Super Duper), your metadata will smoothly follow the files in their new location.

For a short while I toyed with the idea to code a cp/mv replacement, either through a bash or python script, but for the moment I decided that I would like at least to be able to create a backup (snapshot) of all the current Finder/iPhoto comments.

This is pretty easy using Spotlight’s command line utilities. If you want to get a list of the files in the $HOME dir that have a Finder Comment you can simply do:

mdfind “kMDItemFinderComment == ‘*'” -onlyin $HOME

Instead to search for comments added by other tools like iPhoto or iTunes, since those are saved within the kMDItemComment property, you can simply use the following line:

mdfind “kMDItemComment == ‘*'” -onlyin $HOME

So I cooked a small bash script to dump all this information in a file on a regular basis (i.e. when I rsync my data to the server):

DATE=`/bin/date +%Y%m%d_%H%M`
mdfind “kMDItemFinderComment == ‘*'” -onlyin $HOME > .CommentsTmp
mdfind “kMDItemComment == ‘*'” -onlyin $HOME >> .CommentsTmp
touch CommentsBackup_$DATE.comments
while read line
mdls -name kMDItemFinderComment -name kMDItemComment “$line” >> CommentsBackup_$DATE.comments
done < .CommentsTmp

At least now I have a way to extract this data from the store and put it somewhere in ASCII format. Next I’ll try to do a python script to ease the management of the tags and maybe avoid the situations where I inadvertently move a file with the Terminal and loose its tags. If anybody has a better idea, let me know.


Written by theglide

May 14, 2007 at 7:19 pm

Posted in Mac

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: