Adding Keywords
https://discussions.apple.com/thread/4609223?start=0&tstart=0
This is where I got to recently with a script many thanks to all that helped.
The issue I still have is that keywords don't get added to the files labelled AB12NW01234MU2MM_2
The way it works is to find the take the name of the file.
AB12NW01234MU2MM.psd (that is always 16 digits inc Extentsion)
It then checks against a CSV File,
AB12NW01234MU2MM.psd,AB12NW01234MU2MM,504123,Picture of a person,5
It then uses the line above to add the other data to the IPTC/Exif data of the file.
At the same time it still needs to add a checkmark to say that that image has been shot.
The above works with the script, however it does not cater for those images that have _2, _3, _4
With these it needs to do the same but only do it to add information to the file not add the tick mark.
Very difficult to perhaps understand the code, but I hope someone can help me. These are the handlers below
on findNameInCsv(f) -- search the exact name from the beginning of each line ***
set {tid, text item delimiters} to {text item delimiters, {":"}}
set tName to last text item of f -- get the filename
set text item delimiters to "."
set thisExt to last text item of tName-- get name extension
set text item delimiters to tid
if thisExt is in extension_list then
set tc to (count thisExt) + 2
set last3chars to text -(tc + 2) thru -tc of tName-- get last 3 characters before name extension--> _02
else -- no extension
set last3chars to text -3 thru -1 of tName-- get last 3 characters --> _02
end if
--*** true if "_02" .... "_12" ***--tell last3chars to set b to it starts with "_" and (text 2 is "0" and text 3 is in "23456789" or text 2 thru 3 is in {"10", "11", "12"})
try
if b then set tSku to text 1 thru 16 of tName-- the begining 16 digits, I presume the first 16 characters in the nameon error
set b to false
end try
set n to tName & ","
set tc to counto'scsvText
repeat with i from 1 to tc
set t to item i of o's csvText
if not b and t starts with n or b and (t starts with tSku or t starts with "✔," & tSku) then -- found
set x to ""
if not b then set item i of o's csvText to "✔," & t
set text item delimiters to {","}
try
set x2 to text item 2 of t --get original Name
set x3 to (text item 3 of t) & "ALTERNATIVE CODE :_" --get alternative Sku
set x4 to text item 4 of t -- get the keyword
try
set x5 to text item 6 of t--get AIR OR SEA RECORD
on error
set x5 to ""
end try
end try
set text item delimiters to tid
-- exiftool add the keywords to EXIF
if x4 is not "" then do shell script "/usr/bin/exiftool -P -overwrite_original_in_place -keywords+=" & (quoted form of x4) & " -headline=" & (quoted form of x2) & " -source=" & (quoted form of x5) & " " & quoted form of POSIX path of f
return (not b)
end if
end repeat
return false
end findNameInCsv
on write_to_file(the_file, tList) -- update CSV file ***
set n to 0
set n1 to 0
set tc to counto'scsvText
repeat with i from 1 to tc--- ** move lines with check mark to the bottom **
set L to item i of o's csvText
if L is not "" then -- not a blank lines
set n1 to n1 + 1 -- count this valid line
if "✔" is in L then
set n to n + 1 -- count this check mark
set end of o's csvText to L
set item i of o's csvText to missing value
end if
else
set itemi of o'scsvText to missing value-- remove this blank lines
end if
end repeat
set {tid, text item delimiters} to {text item delimiters, {return}}
set the_data to (text of o'scsvText) as text-- convert list of lines to text
set text item delimiters to tid
try
set openfile to open for accessthe_file with write permission
set eof of openfile to 0
writethe_datatoopenfilestarting at 0 as «class utf8»
close accessopenfileon error
try
close accessthe_fileend try
end try
return n1 = n-- if the number of lines equal the numbers of check marks
end write_to_file
Mac Pro, OS X Mavericks (10.9)