Main Menu

add tag if

Started by j99mac, July 17, 2014, 08:32:45 AM

Previous topic - Next topic

j99mac

Is there a way to write a command to add a tac if the tag dose not match.
I am looking to only add the Artist Tag if it is not all ready added with my custom artist name.
I found -if. How to I use it with exiftool -artist="$Artist" "$imagepath"  ?

Phil Harvey

The command could look like this:

exiftool "-artist=Some Name" -if "not $artist or $artist !~ /Some Name/" FILE

(use single quotes instead of double if you are on Mac or Linux)

- 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 ($).

j99mac

This is what I try


artist="artist name"
echo "Enter the file directory of Images Directory "
   read input_variable
exiftool "-artist=artist name" -if "not $artist or $artist !~ /Some Name/" "$input_variable"
exiftool "$input_variable" -r -artist

What is ~ /Some Name/ ? I want to run this on all files in a directory and if it fails then add he artist

Hayo Baan

Hi,

!~/Some Name/ is a perl regular expression for not matching Some Name. If you like to know more about perl regular expressions, google perldoc perlre. Or, if you are on a Mac, Unix, or Linux system, type perldoc perlre on the command line.

Hope this helps,
Hayo
Hayo Baan – Photography
Web: www.hayobaan.nl

j99mac

This what I tryed

exiftool "-artist=Some Name" -if "not $artist or $artist !~ /Some Name/" "$input_variable" -r
How do I get the script to add the artist tag f it is not all ready in the file

Phil Harvey

I think your problem is with your batch file variables.  If you type the command I gave at the command line, then it should add the Artist "Some Name" if it doesn't already exist.

In my command, "FILE" represents one or more file and/or directory names.

- 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 ($).

j99mac

This is what I get when I entered the command in terminal

exiftool "-artist=Some Name" -if "not $artist or $artist !~ /Some Name/" ~/Desktop/images

exiftool "-artist=Some Name" -if "not $artist or $artist ~/Library/Preferences/com.apple.Terminal.plist /Some Name/" ~/Desktop/images
    1 directories scanned
    1 files failed condition
    0 image files read

Phil Harvey

Your first command should work, but there is something terribly wrong with your second command.

This is what I get:

> exiftool -artist a.jpg
> exiftool "-artist=Some Name" -if "not $artist or $artist !~ /Some Name/" a.jpg
    1 image files updated
> exiftool -artist a.jpg
Artist                          : Some Name
> exiftool "-artist=Some Name" -if "not $artist or $artist !~ /Some Name/" a.jpg
    1 files failed condition


- 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 ($).

j99mac

I want to run the script on a directory of images

Phil Harvey

Yes.  So instead of "a.jpg" in my commands, use the directory name.
...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 ($).

j99mac

This is what I get when I changed the jpg to my file path

exiftool "-artist=Some Name" -if "not $artist or $artist !~ /Some Name/" ~/Desktop/Images
exiftool "-artist=Some Name" -if "not $artist or $artist ~/Library/Preferences/com.apple.Terminal.plist /Some Name/" ~/Desktop/Images
    1 directories scanned
    0 image files read

Hayo Baan

You're on a mac, so try changing the quotes to single quotes. This should solve your problem (within double quotes, the shell still tries to do variable expansion and other stuff like interpreting the ! as a shell history reference, that's what's causing the funny path).

Cheers,
Hayo
Hayo Baan – Photography
Web: www.hayobaan.nl

Phil Harvey

Ah, I get it now.  The "~" in your command was expanded by the shell because you used the wrong quotes.  That is why it looked like you had 2 commands.

Hmm.  But if I try this command on my Mac, in a C-shell I get "artist: Undefined variable.", and in a Bourne shell I get "bash: !~: event not found".  Oh well.  So maybe I don't understand after all.

But using the proper quotes as Hayo and I mentioned will likely solve the problem.

- 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 ($).

Hayo Baan

Quote from: Phil Harvey on July 17, 2014, 03:23:30 PM
Hmm.  But if I try this command on my Mac, in a C-shell I get "artist: Undefined variable.", and in a Bourne shell I get "bash: !~: event not found".  Oh well.  So maybe I don't understand after all.

Hi Phill, on your machine it doesn't find !~ because you didn't have a shell command starting with a ~. I did and it gave the same result as for j99mac (albeit with a different expansion of !~). I'm running the bash shell (the default), and there non-existing vars don't give me an error either (they just expand to an empty string). Interesting that you do get an error. What version of the OS are you on? I'm on 10.9.4.

(Oh, I guess you must have set -o nounset active, which I don't. Hmm, perhaps a smart thing to do...)
Hayo Baan – Photography
Web: www.hayobaan.nl

Phil Harvey

I'm on 10.8.5 here, but I have set my default shell to tcsh.

- 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 ($).