ExifTool Forum

ExifTool => Newbies => Topic started by: j99mac on November 04, 2021, 10:26:22 AM

Title: write to tag or use if not
Post by: j99mac on November 04, 2021, 10:26:22 AM
What is better to do write to a tag or use exiftool -if 'not $TagName.

I am looking to only update images that do not have tag filed in and or do not match tag value.

and combine 2 tag in one script

artist and ModifyDate
Title: Re: write to tag or use if not
Post by: StarGeek on November 04, 2021, 11:02:32 AM
You can't use use the -if option (https://exiftool.org/exiftool_pod.html#if-NUM-EXPR) to conditionally write one tag and unconditionally write another.

But if you're writing the same thing to artist that already exists and you're writing new value for ModifyDate for all file, just write both at the same time.  For example, if half your files already have Artist set to "me" but you're going to change the ModifyDate on all the files anyway, go ahead an rewrite Artist, e.g. -Artist=Me -ModifyDate="2021:11:04 12:00:00".  That would be faster than running two separate commands.
Title: Re: write to tag or use if not
Post by: j99mac on November 04, 2021, 11:14:35 AM
This is what I tryed
exiftool -r -overwrite_original -artist="$Artist" -ModifyDate=now $path

what about using if vs just over wring command?
Title: Re: write to tag or use if not
Post by: StarGeek on November 04, 2021, 11:34:45 AM
That's the same question I just answered.
Title: Re: write to tag or use if not
Post by: j99mac on November 09, 2021, 09:02:34 AM
would this work
to add a Tag if no tag data is found
exiftool -if "not $ModifyDate" -ModifyDate=now
Title: Re: write to tag or use if not
Post by: StarGeek on November 09, 2021, 10:22:32 AM
Test it to see if it's what you want.
Title: Re: write to tag or use if not
Post by: j99mac on November 09, 2021, 10:55:05 AM
when I run it I get     1 files failed condition
Title: Re: write to tag or use if not
Post by: StarGeek on November 09, 2021, 11:23:29 AM
On Mac/Linux, you use single quotes around anything with a dollar sign, otherwise the shell/terminal treats it as a shell variable.
Title: Re: write to tag or use if not
Post by: j99mac on November 09, 2021, 11:46:33 AM
This is what I am running

I am combing to it with adding Artist tag

exiftool -r -overwrite_original -if "not defined $ModifyDate" -ModifyDate=now -artist="$Artist" "$path"
Title: Re: write to tag or use if not
Post by: Phil Harvey on November 09, 2021, 02:06:02 PM
What system are you running?  It seems as if you are using Unix shell variables for $Artist and $path.  If in a Unix shell, you need to do this as StarGeek said:

exiftool -r -overwrite_original -if 'not defined $ModifyDate' -ModifyDate=now -artist="$Artist" "$path"

- Phil
Title: Re: write to tag or use if not
Post by: j99mac on November 09, 2021, 03:08:20 PM
I am running the script on OS X
When I run it I get the error Error: Not a valid TIFF (looks more like a MacOS)
Then when I check the files they have ModifyDate, Artist
Title: Re: write to tag or use if not
Post by: Phil Harvey on November 09, 2021, 03:28:42 PM
You're running the command on a MacOS resource file if you're getting that error.

- Phil
Title: Re: write to tag or use if not
Post by: j99mac on November 09, 2021, 03:52:05 PM
This is what I am running
exiftool -r -overwrite_original -if 'not defined $ModifyDate' -ModifyDate=now -artist="$Artist" "$path"

and there is just tiff in my folder
Title: Re: write to tag or use if not
Post by: Phil Harvey on November 09, 2021, 10:05:42 PM
Is "$path" the directory name?  If so, you are probably running ExifTool on 2 files.  A TIFF file and the hidden MacOS file.  Use -i HIDDEN to ignore hidden files.

- Phil
Title: Re: write to tag or use if not
Post by: j99mac on November 10, 2021, 09:35:06 AM
I am also trying to add tag data if it is missing or there is no data in the field. for example is made does not exist
-if $make =~ ""