Hello again,
I have the following code working fine for creating the set of keywords and then copying the keywords to subject. But I'd like to figure out how to do this in one command line vs two command lines. Any suggestions? I've tried several variations of tagsfromfile and addtagsfromfile along with @ and/or the file name but I usually get a Warning: No writable tags set from test1.jpg so I'm either doing things in the wrong order or I don't know what. Thanks for any guidance. I read the manual section on this but still a bit confused since I can't seem to get it working.
#exiftool -Sep ', ' '-keywords+<$IPTC:Sub-location, $IPTC:City, $IPTC:Province-state, r$XMP-xmp:Rating, $EXIF:DateTimeOriginal' -d %Y "$file"
#exiftool -tagsfromfile @ -"IPTC:Keywords>XMP:Subject" $file
Try this:
exiftool -tagsfromfile @ '-XMP:Subject-<IPTC:keywords' '-XMP:Subject+<IPTC:keywords' '-keywords+<IPTC:Sub-location' '-keywords+<IPTC:City' '-keywords+<IPTC:Province-state' '-keywords+<r$XMP-xmp:Rating' '-keywords+<EXIF:DateTimeOriginal' '-XMP:subject+<IPTC:Sub-location' '-XMP:subject+<IPTC:City' '-XMP:subject+<IPTC:Province-state' '-XMP:subject+<r$XMP-xmp:Rating' '-XMP:subject+<EXIF:DateTimeOriginal'-d %Y "$file"
Or for a command like this, using the -@ makes sense:
exiftool -@ my.args "$file"
where "my.args" is:
-tagsfromfile
@
-XMP:Subject-<IPTC:keywords
-XMP:Subject+<IPTC:keywords
-keywords+<IPTC:Sub-location
-keywords+<IPTC:City
-keywords+<IPTC:Province-state
-keywords+<r$XMP-xmp:Rating
-keywords+<EXIF:DateTimeOriginal
-XMP:subject+<IPTC:Sub-location
-XMP:subject+<IPTC:City
-XMP:subject+<IPTC:Province-state
-XMP:subject+<r$XMP-xmp:Rating
-XMP:subject+<EXIF:DateTimeOriginal
-d
%Y
Here I have gone to some trouble to preserve the original XMP:Subject and add the original IPTC:Keywords without creating duplicate entries. After this, the new Keywords/Subject values are added. FAQ 17 (https://exiftool.org/faq.html#Q17) discusses this technique.
- Phil
Thanks! This is what I needed to make it work more efficiently. I did need to make two changes:
1) I needed to be more specific and use XMP-dc:Subject because otherwise I received the error: Warning: Shift value for XMP-pdf:Subject is not a number
2) I needed to use -addtagsfromfile instead of -tagsfromfile
My final script is below:
#!/bin/bash
for file in "$@"
do
exiftool -@ ekw.args "$file"
exiftool -Sep '!!' -a -u -g1 -key* -subject* -filename "$file" #Printout final keywords for each photo
done
With ekw.args file:
-addtagsfromfile
@
-XMP-dc:Subject-<IPTC:keywords
-XMP-dc:Subject+<IPTC:keywords
-keywords+<IPTC:Sub-location
-keywords+<IPTC:City
-keywords+<IPTC:Province-state
-keywords+<r$XMP-xmp:Rating
-keywords+<EXIF:DateTimeOriginal
-XMP-dc:subject+<IPTC:Sub-location
-XMP-dc:subject+<IPTC:City
-XMP-dc:subject+<IPTC:Province-state
-XMP-dc:subject+<r$XMP-xmp:Rating
-XMP-dc:subject+<EXIF:DateTimeOriginal
-d
%Y
I essentially use this script to process all photos upon export from Aperture before they are uploaded to Smugmug. I'm diligent about ensuring all photos in Aperture have metadata for location, rating, and any keywords prior to export (in fact if any are empty, the script fails intentionally). Then in smugmug I'm able to create dynamic galleries, etc. based on keywords. I also use exiftool to rename all files prior to import into Aperture (have been doing that for years - thanks!).
Quote from: allobrogica on November 16, 2014, 07:52:08 AM
2) I needed to use -addtagsfromfile instead of -tagsfromfile
Yes, I should have realized this. Good catch.
- Phil
Quote from: allobrogica on November 16, 2014, 07:52:08 AM
...This is what I needed to make it work more efficiently....
Now that your commands are working, you can investigate options that increase speed and efficiency.
For example:
-r "Recursively process files in subdirectories."
-execute "Allows multiple commands to be executed from a single command line."
-common_args "All arguments following this option are common to all executed commands when
-execute is used."
Perhaps
exiftool -@ ekw.args -execute -Sep '!!' -a -u -g1 -key* -subject* -filename -common_args -r DIRor
exiftool -@ ekw.args -execute -Sep '!!' -a -u -g1 -key* -subject* -filename -common_args -@ FileContainingListOfFilePaths.txtcan be used to avoid any looping structure in your script or avoid using a script completely.
Excellent, thanks again for the guidance. Since I want to be able to use this command set on either one file, wildcard set of files or a directory, I have changed to the script accordingly to be compatible with any of these argument variations sent to the bash script. My script currently won't handle files/paths with spaces in them, but I never have image files with spaces anyway.
#!/bin/bash
files=( $@ )
exiftool -@ ekw.args -execute -Sep '!!' -a -u -g1 -key* -subject* -filename -common_args -r ${files[@]}
It's lightning fast now (a couple seconds now for 60 files vs 15+ seconds before because of the looping and re-running exiftool each time). Multiply by lots of photos and that's a huge savings.
Example output:
$ ekw test*.jpg
2 image files updated
======== test2.jpg
---- System ----
File Name : test2.jpg
---- IPTC ----
Keywords : Smitten Ice Cream!!San Francisco!!California!!r2!!2014
---- XMP-dc ----
Subject : Smitten Ice Cream!!San Francisco!!California!!r2!!2014
======== test3.jpg
---- System ----
File Name : test3.jpg
---- IPTC ----
Keywords : Art Soul Festival!!Downtown Oakland!!Oakland!!California!!r1!!2014
---- XMP-dc ----
Subject : Art Soul Festival!!Downtown Oakland!!Oakland!!California!!r1!!2014