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

HereComeTheBugs

macrumors newbie
Original poster
Jul 15, 2004
10
0
I have a monumental problem...

My parents over the years have been scanning in old photos as jpeg files. As they have been doing that they have been making notes on who/what is in the photo in the comments section of the file properties -- The spotlight comments field (!). (Select a file and do a get info or press Command-I). Unbeknownst to them, this info doesn't transfer when you move the file to a thumb-stick and put it on a Windows machine OR if you back it up to something like Google Drive/Drop box etc. Over the years they have amassed thousands of photos with comments... I really wish I would have know they are doing this and stopped them. Anyway my thought is a better way of doing this would be to have a txt file with the same name as the jpeg file and put the comments in there...

So, question, does anyone know if there is a program that will help me bulk export the comments to a txt file? What about Automator? Can that automate the process of taking a bunch of jpeg files, reading the comments section of the file properties on said files, then creating individual txt files with the same name as the photo and pasting those comments into the txt file? Any tips on how to actually do this would be appreciated. I've toyed with Automator and I cant seem to figure out how to do it.

I'm dying, otherwise it's going to take many many hours... possibly weeks/months to manually correct this.
 
I should also say that I posted this to the macOS Stack exchange. The response I got was to use the following terminal command.

mdfind "kMDItemFinderComment=*" | xargs mdls -name kMDItemFinderComment -name kMDItemFSName -r | xargs -0 -n1 echo | awk 'NR%2==1{printf "\"" $0 "\","} NR%2==0{print "\"" $0 "\""}'

When I try that however I get an error saying Xargs: unterminated quote.

I tried putting -0 after xargs but then I get an error saying xargs: insufficient space for argument

That said, all of the above is basically a foreign language to me. I've tried for hours to search and understand the errors. Unfortunately the person who said to use the above terminal command on stack exchange didn't reply to my questions on the errors... Any assistance with the code or a different solution is GREATLY appreciated.
 
Here's another oneliner for you. It'll create individual .txt files that are each colocated with the file they were extracted from:

Code:
mdfind "kMDItemFinderComment=*" | while read -r FILE_PATH; do mdls -name "kMDItemFinderComment" --raw "${FILE_PATH}" >"${FILE_PATH}_comment.txt"; done

Rather than operating on the entire disk, you might want to limit it to a specific directory,
e.g. by adding the arguments -onlyin "${HOME}/MyStuff/Photos" after mdfind
 
Last edited:
Here's another oneliner for you. It'll create individual .txt files that are each colocated with the file they were extracted from:

Code:
mdfind "kMDItemFinderComment=*" | while read -r FILE_PATH; do mdls -name "kMDItemFinderComment" --raw "${FILE_PATH}" >"${FILE_PATH}_comment.txt"; done

Rather than operating on the entire disk, you might want to limit it to a specific directory, e.g. by adding -onlyin "${HOME}/MyStuff/Photos" after mdfind
I could cry, THANK YOU! You have no idea how long I have been searching for a fix for this. I just ran that command and its WORKING!
 
FYI, I ran a check last night and found they had over 7,500 photos with comments. This is unbelievably EPIC. You saved me sooooo much time. Thanks again.
 
You're welcome 😀 Unix shell scripting is cool like that... learn it once and then you will be able to do useful tricks for decades!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.