Q: Image checklist and add keywords
Image check list and adding keywords,
What I would like the script to do.
As images (PSD) arrive in the folder.
tick it off the checklist.
Use the checklist to add keywords to the PSD file.
If all the images are in the folder and match the completed checklist then turn the folder label green.
I'm already using this script, this allows me to turn the files green if they fit the correct ratio. So ideally I will sandwich the new script within this one as they operate as watch folder via the LaunchDaemons.
property type_list : {"TIFF", "JPEG", "PNGf", "PICT"}
property extension_list : {"tif", "tiff", "jpg", "jpeg", "png", "pict", "psd"}
--BH
try
tell application "Finder" to set bh_folders to (get every folder of desktop whose name starts with "BH")
if bh_folders is not {} then
set aBHFolder to item 1 of bh_folders
tell application "Finder" to set bh_files to every file of the aBHFolder whose ¬
file type is in the type_list or name extension is in the extension_list
repeat with i from 1 to the count of bh_files
set bh_path to (item i of bh_files) as string
tell application "Image Events"
set bh_image to open file bh_path
copy the dimensions of bh_image to {xbhwidth, ybhheight}
close bh_image
end tell
set bhRatio to 1348 / 1832
if xbhwidth / ybhheight is greater than bhRatio - 1.0E-3 and xbhwidth / ybhheight is less than bhRatio + 1.0E-3 then
my BH_CorrectRatio(xbhwidth, ybhheight, bh_path)
else
my BH_CheckRatio(xbhwidth, ybhheight, bh_path)
end if
end repeat
end if
on error error_message
display dialog error_message buttons {"OK"} default button 1
--UPPERCASE CHANGER
set the source_folder to aBHFolder
tell application "Finder"
repeat with this_item in entire contents of source_folder
set the current_name to the name of this_item as text
set the name of this_item to my change_case(the current_name, "upper")
end repeat
end tell
--UPPERCASE CHANGER
end try
on BH_CorrectRatio(xbhwidth, ybhheight, bh_path)
tell application "Finder"
set label index of document file bh_path to 6
end tell
end BH_CorrectRatio
on BH_CheckRatio(xbhwidth, ybhheight, bh_path)
tell application "Finder"
set label index of document file bh_path to 5
end tell
end BH_CheckRatio
--END BH
-- Burt
try
tell application "Finder" to set Burt_folders to (get every folder of desktop whose name starts with "Burt")
if Burt_folders is not {} then
set aBurtFolder to item 1 of Burt_folders
tell application "Finder" to set Burt_files to every file of the aBurtFolder whose ¬
file type is in the type_list or name extension is in the extension_list
repeat with i from 1 to the count of Burt_files
set Burt_path to (item i of Burt_files) as string
tell application "Image Events"
set Burt_image to open file Burt_path
copy the dimensions of Burt_image to {xBurtwidth, yBurtheight}
close Burt_image
end tell
set BurtRatio to 1020 / 1385
if xBurtwidth / yBurtheight is greater than BurtRatio - 1.0E-3 and xBurtwidth / yBurtheight is less than BurtRatio + 1.0E-3 then
my Burt_CorrectRatio(xBurtwidth, yBurtheight, Burt_path)
else
my Burt_CheckRatio(xBurtwidth, yBurtheight, Burt_path)
end if
end repeat
end if
on error error_message
display dialog error_message buttons {"OK"} default button 1
--UPPERCASE CHANGER
set the source_folder to aBurtFolder
tell application "Finder"
repeat with this_item in entire contents of source_folder
set the current_name to the name of this_item as text
set the name of this_item to my change_case(the current_name, "upper")
end repeat
end tell
--UPPERCASE CHANGER
end try
on Burt_CorrectRatio(xBurtwidth, yBurtheight, Burt_path)
tell application "Finder"
set label index of document file Burt_path to 6
end tell
end Burt_CorrectRatio
on Burt_CheckRatio(xBurtwidth, yBurtheight, Burt_path)
tell application "Finder"
set label index of document file Burt_path to 5
end tell
end Burt_CheckRatio
on Season_CorrectRatio(xSeasonwidth, ySeasonheight, Season_path)
tell application "Finder"
set label index of document file Season_path to 6
end tell
end Season_CorrectRatio
on Season_CheckRatio(xSeasonwidth, ySeasonheight, Season_path)
tell application "Finder"
set label index of document file Season_path to 5
end tell
end Season_CheckRatio
-- AppleScript 'change_case' handler
on change_case(this_text, this_case)
if this_case is "lower" then
set the comparison_string to "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
set the source_string to "abcdefghijklmnopqrstuvwxyz"
else
set the comparison_string to "abcdefghijklmnopqrstuvwxyz"
set the source_string to "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
end if
set the new_text to ""
repeat with thisChar in this_text
set x to the offset of thisChar in the comparison_string
if x is not 0 then
set the new_text to (the new_text & character x of the source_string) as string
else
set the new_text to (the new_text & thisChar) as string
end if
end repeat
return the new_text
end change_case
--UPPERCASE CHANGER
The checklist is in the format of a CSV file and looks like this (there is no header line)
Filename, Title, Description, keywords
MA00XX01234AA5BB.PSD, MA00XX01234AA5BB, image of cat, cat paw
" " " "
and so on….
Now when the file arrives in the folder, check it against the checklist add a Y (for yes) or ✔ if that is possible?
NOW Keywords i'll come back to that)
If all the files have a Y or ✔ next to them the file is complete so change the label to green.
Now the keywords.
So when the files arrive in the folder not only will a checkmark be added to the list but I would like it to a take the file ad add the keywords to the file.
In terms of software I have Photoshop CS5, Adobe bridge, however I would like to avoid using them to add the keywords since it will involve reopening the file just to add the keyword, it needs to happen in the background as much as possible.
Now there is ExifTool but like many know from my posts on here I have really no idea how to attempt to implement any of this.
Many Thanks in advance
Matt
iMac, Mac OS X (10.6.8)
Posted on Dec 17, 2012 11:22 PM
Hi,
Try this script:
-----------------
property type_list : {"TIFF", "JPEG", "PNGf", "PICT"}
property extension_list : {"tif", "tiff", "jpg", "jpeg", "png", "pict", "psd"}
script o -- ***
property csvText : {}
end script
--BH
try
tell application "Finder" to set bh_folders to (get every folder of desktop whose name starts with "BH")
if bh_folders is not {} then
set aBHFolder to item 1 of bh_folders
tell application "Finder"
set bh_files to every file of the aBHFolder whose ¬
file type is in the type_list or name extension is in the extension_list
set fName to name of aBHFolder -- to get the basename of the CSV file ***
set checkListFile to (file (fName & ".csv") of folder "keywords" of desktop) as alias -- get the CSV path (alias) ***
end tell
if bh_files is not {} then -- ***
set isChanged to false -- ***
set o's csvText to paragraphs of (read checkListFile as «class utf8») -- get the contents of the CSV file ***
launch application "Image Events" -- ***
repeat with i from 1 to the count of bh_files
set bh_path to (item i of bh_files) as string
tell application "Image Events"
set bh_image to open file bh_path
copy the dimensions of bh_image to {xbhwidth, ybhheight}
close bh_image
end tell
set bhRatio to 1348 / 1832
if xbhwidth / ybhheight is greater than bhRatio - 1.0E-3 and xbhwidth / ybhheight is less than bhRatio + 1.0E-3 then
my BH_CorrectRatio(xbhwidth, ybhheight, bh_path)
else
my BH_CheckRatio(xbhwidth, ybhheight, bh_path)
end if
-- *** find this name in CSV text ***
if (my findNameInCsv(bh_path)) then set isChanged to true -- a check mark was added in CSV text ***
end repeat
if isChanged then -- CSV file must be updated ***
set r to my write_to_file(checkListFile, o's csvText) -- *** update CSV file ***
-- ***if r is true, the checkList is complete so change the folder label to green ***
if r then tell application "Finder" to set label index of aBHFolder to 5 -- ***
end if
set o's csvText to {} -- empty this property to not save his contents when the script quit ***
end if
end if
on error error_message
display dialog error_message buttons {"OK"} default button 1
--UPPERCASE CHANGER
set the source_folder to aBHFolder
tell application "Finder"
repeat with this_item in entire contents of source_folder
set the current_name to the name of this_item as text
set the name of this_item to my change_case(the current_name, "upper")
end repeat
end tell
--UPPERCASE CHANGER
end try
---------- *** added handlers ***
on findNameInCsv(f) -- search the exact name from the beginning of each line ***
set {tid, text item delimiters} to {text item delimiters, {":"}}
set n to (last text item of f) & "," -- get the filename
set text item delimiters to tid
set tc to count o's csvText
repeat with i from 1 to tc
set t to item i of o's csvText
if t starts with n then -- found
if t does not end with "✔" then -- no check mark at end of this line
set x to ""
set item i of o's csvText to t & ",✔" -- add a check mark to the end of this line
set text item delimiters to {","}
try
set x to text item 4 of t -- get the keyword
end try
set text item delimiters to tid
-- exiftool add the keywords to EXIF
if x is not "" then do shell script "/usr/bin/exiftool -P -overwrite_original_in_place -keywords+=" & (quoted form of x) & " " & quoted form of POSIX path of f
return true
end if
return false -- exit the loop (the name was found).
end if
end repeat
return false
end findNameInCsv
on write_to_file(the_file, tList) -- update CSV file ***
set {tid, text item delimiters} to {text item delimiters, {return}}
set the_data to tList as text -- convert list of lines to text
try
set openfile to open for access the_file with write permission
set eof of openfile to 0
write the_data to openfile starting at 0 as «class utf8»
close access openfile
on error
try
close access the_file
end try
end try
set text item delimiters to {"✔"}
set n to count text items of the_data
set text item delimiters to tid
return (count tList) = (n - 1)
end write_to_file
-----------------
it works for the BH folder, as it is similar, you will have no difficulty to modify your script to the other folders.
ExifTool insert keyword to the EXIF keyword tag of the image
I don't put your handlers in this script, because there is no change.
Important: CSV files must be UTF-8 encoded
Posted on Dec 20, 2012 12:56 AM