ExifTool Forum

ExifTool => Newbies => Topic started by: delunar on March 14, 2015, 08:35:10 AM

Title: Not desired results
Post by: delunar on March 14, 2015, 08:35:10 AM
Hello and apologies if this is not the correct forum for such a newbie question. I just discovered this awesome tool and would love to continue to use it.

I'm no expert nor novice for that matter with scripting / command line so I'm sure it's something that i'm just not seeing.

I'm trying to tag some pictures with this script I found over at another site with "key words" and i'm not getting the desired results. When selecting multiple pictures, the first one gets tagged correctly. Yet when the second picture is tagged the keywords doubles up and for the third it triples and so forth. What i want is for each picture to have just one iteration of the tag

example:
picture1.jpg - son daughter
picture2.jpg - son daughter son daughter
picture3.jpg - son daughter son daughter son daughter
picture4.jpg - son daughter son daughter son daughter son daughter
..
..
picture12.jpg - son daughter son daughter son daughter son daughter son daughter son daughter son daughter son daughter son daughter son daughter son daughter son daughter

What i want is for each picture to have just one iteration of the tag.

example:
picture1.jpg - son, daughter
picture2.jpg - son, daughter
picture3.jpg - son, daughter


Below is the script i'm trying to use. Any help fixing the script would be greatly appreciated.


property ExifTool : "/usr/bin/exiftool"
property ExifToolOptionMovie : "-keywords="
property ExifToolOptionImage : "-keywords+="

on run {input, parameters}
   set pathList to ""
   display dialog "Enter Keywords (Separate multiple by comma)" default answer "Papo, Nini" buttons {"Cancel", "OK"} default button 2
   set kWord to text returned of the result
   repeat with i from 1 to count of items of input
      set this_item to item i of input
      set pathList to pathList & space & "\"" & (POSIX path of this_item) & "\"" as string
      tell application "Finder"
         if name extension of this_item is in {"MOV", "mov", "mv4", "m4v", "mp4", "avi"} then
            copy ExifToolOptionMovie to ExifToolOption
         else
            copy ExifToolOptionImage to ExifToolOption
         end if
      end tell
      do shell script ExifTool & space & ExifToolOption & quoted form of kWord & space & "-overwrite_original_in_place -P" & space & pathList
   end repeat
end run
Title: Re: Not desired results
Post by: Phil Harvey on March 14, 2015, 08:46:16 AM
This isn't really the correct forum since this is an AppleScript question and not really an ExifTool thing, but I think I can help anyway.

In your repeat loop, you keep adding file names to pathList, and call exiftool repeatedly without ever clearing the old file names from pathList.  try changing this:

      set pathList to pathList & space & "\"" & (POSIX path of this_item) & "\"" as string

to this

      set pathList to "\"" & (POSIX path of this_item) & "\"" as string

But note that multiple keywords will not be added separately.  You should add this to the command to write the keywords properly:  -sep ", "  (see FAQ 17 (https://exiftool.org/faq.html#Q17) for details)

- Phil
Title: Re: Not desired results
Post by: delunar on March 14, 2015, 09:08:36 AM
Phil, yes you are correct. After i posted it, i was about to edit and make that same statement. Apologies and i'll learn from this and keep all future questions related to exiftool. Thanks for your reply.