ExifTool Forum

ExifTool => Newbies => Topic started by: deathrobot on February 08, 2015, 07:57:42 PM

Title: Testing if Exif DateTime Original is not empty
Post by: deathrobot on February 08, 2015, 07:57:42 PM
Hello. I'm working on an automatic photo management system and would like to run a shell script in Hazel to test if a photo contains any data in the Exif Date Time Original field. If it does, I'll run DIM to organize, but if it doesn't I just want to tag the file and move it to another folder for manual sorting. Having trouble figuring out what the shell script would be. This seems to be true whether the file has exif date created or not:

exiftool -if $datetimeoriginal $1

Thanks for any help with this. I know nothing about PERL, but am frustrated that Spotlight will only use the file Date Created info instead of extracting Exif info and would really like to get this to work. Any help is much appreciated!
Title: Re: Testing if Exif DateTime Original is not empty
Post by: Phil Harvey on February 09, 2015, 07:07:58 AM
You need to protect the first "$" against shell interpolation by quoting $datetimeoriginal:

exiftool -if '$datetimeoriginal' $1

This will return 0 if DateTimeOriginal exists, or 1 otherwise.  You might want to suppress other output by adding a dummy tag name:

exiftool -if '$datetimeoriginal' -dummy $1

- Phil
Title: Re: Testing if Exif DateTime Original is not empty
Post by: deathrobot on February 11, 2015, 07:36:33 PM
Perfect. Thank you.
Title: Re: Testing if Exif DateTime Original is not empty
Post by: deathrobot on February 16, 2015, 03:35:42 PM
Turns out this fails in the situation where there is a datetimeoriginal tag that is empty, as opposed to the tag not being there at all (in which case it works). Is there a shell script that could test for both situations, i.e.:

exiftool -if '$datetimeoriginal' -dummy "$1"
     or
-if [datetimeoriginal is empty] -dummy "$1"

Thanks,
Michael
Title: Re: Testing if Exif DateTime Original is not empty
Post by: Phil Harvey on February 16, 2015, 06:40:17 PM
It sounds like DateTimeOriginal is probably filled with spaces or something like that.  You can test to see if it contains any digit with this:

exiftool -if '$datetimeoriginal =~ /\d/' ...

- Phil
Title: Re: Testing if Exif DateTime Original is not empty
Post by: deathrobot on February 16, 2015, 06:57:54 PM
Thanks, Phil. After quite a bit of looking through the forum posts, I was able to use this:

exiftool -if 'not defined $datetimeoriginal or $datetimeoriginal =~ /(^\s*$)/' "$1"

Is your version of the part of this statement that comes after the "or" more appropriate?
Title: Re: Testing if Exif DateTime Original is not empty
Post by: Phil Harvey on February 17, 2015, 07:17:46 AM
On Mac/Linux a condition should fail if the tag isn't defined.  (But for some reason I don't quite understand this isn't true in Windows, so here you must test for not defined.)

Your expression (after "or") returns true if DateTimeOriginal is empty or contains all spaces.  This will work fine.  (Mine was the opposite logical sense, so you would have to use $datetimeoriginal !~ /\d/ to have a similar effect.)

- Phil
Title: Re: Testing if Exif DateTime Original is not empty
Post by: deathrobot on February 17, 2015, 09:52:06 AM
Thank you!

Michael