Adding MacOS tags to files in a folder

Started by BennyP, February 15, 2023, 09:11:49 AM

Previous topic - Next topic

BennyP

Hi

Exiftool has been an invaluable way of extracting lens info for my wedding video footage.  I need to use MacOS tags to label each file, so I can search my entire HDD by lens type.  Currently, I use the following code and then have to manually apply MacOS tags to the files, one batch at a time.  This is taking hours.

Exiftool -filename -lenstype -FocalLength -csv (folder location)

Is there any way I can alter this code so it automatically reads the "-lenstype" value and writes an appropriate tag to each file in the folder?

Here is my thinking in layman's terms:

Exiftool -filename -lenstype -FocalLength -csv (folder location)
IF -lenstype = LUMIX S 35/F1.8 THEN write "lumixs35" as a tag
IF -lenstype = LUMIX S 50/F1.8 THEN write "lumixs50" as a tag
IF -lenstype = LUMIX S 85/F1.8 THEN write "lumixs85" as a tag

Many thanks in advance to anybody who is able to help me.  It's a job I do every year as I like to post some footage on my Youtube Channel but I need to be able to tell viewers which lens was used for every shot.  This job currently takes me around 1 day each year to do manually :(. Thanks, Ben

Phil Harvey

"Write it as a tag" ... where?

Something like this could work:

exiftool "-TAG<${lenstype;s/(\w+) (\w+) (\d+).*/\L$1$2$3/" DIR

This uses a substitution expression in ExifTool's advanced formatting feature to reformat the LensType as you wanted.

TAG is the tag you want to write.  You'll have to figure out where to put this.  You mentioned a MacOS tag.  ExifTool can write MDItemUserTags (see here for details), which may be what you want.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

BennyP

Thanks Phil

I'm looking to write it as a MacOS system tag...it's what you create when you click on the 'tag button"...see the link here...

https://ibb.co/0qQqK19

I tried the code you suggested but it did produced the following message...

https://ibb.co/hdNFNBY

Would it need tweaking for the purpose I've described?

Thanks, Ben

Phil Harvey

I don't see any message in your screen capture.

As I said, MDItemUserTags may be what you want.  Use this instead of "TAG" in the command.  For this to work you need the "tag" utility to be installed.  See the link I referenced.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

StarGeek

Quote from: BennyP on February 15, 2023, 10:15:52 AMI tried the code you suggested but it did produced the following message...

As Phil said
Quote from: Phil Harvey on February 15, 2023, 09:35:44 AMTAG is the tag you want to write.  You'll have to figure out where to put this.

You replace TAG with the name of the actual tag you want to copy to.  We don't know what that is.

Find a file that has data already set.  Then you want to use the command in FAQ #3 with the addition of the -API RequestAll option to see all the tags in the file.  Figure out which tag it is and replace TAG with that name
exiftool -G1 -a -s -API RequestAll=2 file.jpg
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

BennyP

Thanks Phil Harvey and StarGeek

I feel like I'm starting to make progress.  I've established that MDItemUserTags is the code that I've needed to use so I've included it.  I've also installed Home-brew and tried, unsuccessfully, to install their TAG code.

Here is a video of how things are looking now:
MDItemUserTags

https://www.youtube.com/watch?v=zNy5OQNeAb0

To be honest, creating the MacOS tags is not 100% essential to my end goal here.  I just want to find the easiest possible way of adding any kind of tag/keyword/piece of data that will allow me to search a bunch of folders within the 'Finder' on MacOS, and find all video files that were shot with a particular lens.  If yourselves or anybody knows an easier / more streamlined way of achieving this goal with Exiftool, that would be a huge help.

Many thanks for your continued help, Ben :)

greybeard

#6
The tags visible in finder are resource values associated with the file URL - they are not tags contained within the file as is the case with EXIF metadata.
Its relatively easy to access or update them within a macOS program (written in Swift or C++) - not sure about exiftool though.

(I'd never given any thought to this before but I just wrote a program to tag my image files so that they show up with a green dot in finder if they come from a Fujifilm camera)