Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

Perpetua:2011-01-16 ashley$ mdls IMAG0107.jpg

...

kMDItemComment = "Cat with is tongue out."

So, here's my question. xattr can be used to modify some attributes. For example:

Perpetua:2011-01-16 ashley$ xattr -l IMAG0107.jpg 
com.apple.metadata:kMDItemFinderComment:
00000000  62 70 6C 69 73 74 30 30 50 08 00 00 00 00 00 00  |bplist00P.......|
00000010  01 01 00 00 00 00 00 00 00 01 00 00 00 00 00 00  |................|
00000020  00 00 00 00 00 00 00 00 00 09                    |..........|
0000002a
Perpetua:2011-01-16 ashley$ 

But this isn't the attribute I want to edit. I imagine this is because kMDItemComment is an iPhoto-specific piece of metadata. My question would be, how do I go about editing it?

share|improve this question
    
The above file is a photo, with a description that I added from within iPhoto. –  Harv Jan 17 '11 at 19:46
    
I take it you've tried apple.stackexchange.com/questions/6438/… –  Nathan Greenstein Jan 17 '11 at 19:52
    
@Nathan In fact, I was trying to answer that question, that's how I figured out where/how the metadata was stored. Now I am curious as to how one edits it myself.. and I will point the author of that question over this way if someone has a solution. :-) –  Harv Jan 17 '11 at 19:54
    
You mean how to edit the XML files, or how to get your changes to stick? –  Nathan Greenstein Jan 17 '11 at 20:12
1  
@mankoff Yes, and that's the problem. kMDItemFinderComment comes from com.apple.metadata.. kMDItemComment seems to be from elsewhere, and I'm not sure where. I suspect iPhoto-specific metadata, but I don't know how to access it properly in order to write it. –  Harv Jan 20 '11 at 2:15
show 6 more comments

3 Answers 3

The OpenMeta project is using the extended attributes to store their tags. The source code is available at https://code.google.com/p/openmeta/. Part of that project are open meta command line tools.

This command line tool does operate on pre-defined set of attributes used by OpenMeta, but as it is open source, it can be easily adapted to allow additional command line setting for setting/reading other extended attribute.

Not direct solution, but a path to a solution ?

share|improve this answer
    
Thanks! I will check it out. –  Harv Jan 23 '11 at 3:44
    
@Mira A. I just checked - there's only one command line tool. It only seems to support one extended attribute, and that's the one OpenMeta uses for ratings and such. Thanks for pointing it out, but it doesn't look like it'll do what I want... –  Harv Jan 23 '11 at 3:46
add comment

com.apple.metadata:kMDItemFinderComment is in binary property list format. Using xattr -p -l -x | tail +2 gives you just the hex dump of the attribute. You can then pipe that into xxd -r to turn that back into a binary file.

From there you can open that file in Apple's Property List Editor, assuming you have the Developer Tools installed. You can then edit the property visually.

You should then be able to reapply the edited value to the file using xxd -p -x and xattr -w -x.

This is all much more messy than one really wants for a single property that's just a string.

share|improve this answer
    
Hmm. I can already get the ASCII/Binary equivalent by doing xattr -l <foo>.jpg. The string comes back to "bplist00P".. which I'm not sure what to do with. –  Harv Jan 23 '11 at 4:09
    
That's not the string. That's the "magic" at the start of the binary property list file format. In the example above, the string is actually the empty string. –  ohmantics Jan 23 '11 at 8:21
    
If you're working with binary plist files, then plutil -convert xml1 file.plist might be helpful. –  user588 Jan 24 '11 at 21:51
    
I haven't been able to make this work. Thanks for the suggestions though. –  Harv Jan 26 '11 at 23:55
add comment

One can do this in the "Mac" way (by AppleScript), using the following script setFinderComment.scpt

#!/usr/bin/osascript
on run argv
    set filePath to POSIX file (item 1 of argv)
    set fileComment to item 2 of argv
    set theFile to filePath as alias
    tell application "Finder" to set comment of theFile to fileComment
end run

Then you make it executable chmod a+x setFinderComment.scpt and use as

setFinderComment.scpt filename comment
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.