MattJayC

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

Close

Q: Image checklist and add keywords

  • All replies
  • Helpful answers

Previous Page 2
  • by MattJayC,

    MattJayC MattJayC Jan 7, 2013 1:32 AM in response to Jacques Rioux
    Level 1 (5 points)
    Desktops
    Jan 7, 2013 1:32 AM in response to Jacques Rioux

    I'm liking it, I combined the 2 as I like both ideas, as soon as I replace the findNameInCsv(f) handler it also adds in 'missing value'.

     

    Like this

     

    ✔,DJ30ER06038CR1AG.PSD,DJ30ER06038CR1AG,,Beige stone,21,missing value

     

    Can you help there too?

    Many Thanks once again!

  • by MattJayC,

    MattJayC MattJayC Jan 7, 2013 4:52 AM in response to MattJayC
    Level 1 (5 points)
    Desktops
    Jan 7, 2013 4:52 AM in response to MattJayC

    Do ignore above my error I removed the addition of the weeknumber so is was trying to put nothing in its place.

     

    All working well now

     

    Thanks again!

  • by MattJayC,

    MattJayC MattJayC Jan 7, 2013 9:41 AM in response to Jacques Rioux
    Level 1 (5 points)
    Desktops
    Jan 7, 2013 9:41 AM in response to Jacques Rioux

    Sorry I know I should think about these things first would you be able to help me add this to it as well?

     

    Everything as above is fine. I have some images that are labeled "_2", upto about "_12" at the end of them, but not always. I would like to be able to add the keywords to these files too, but not do the checkmark thing in the csv file.

     

    Is that something that can be done too?

  • by Jacques Rioux,

    Jacques Rioux Jacques Rioux Jan 7, 2013 5:36 PM in response to MattJayC
    Level 4 (3,408 points)
    Mac OS X
    Jan 7, 2013 5:36 PM in response to MattJayC

    Hi,

     

    MattJayC wrote:

     

    Everything as above is fine. I have some images that are labeled "_2", upto about "_12" at the end of them, but not always. I would like to be able to add the keywords to these files too, but not do the checkmark thing in the csv file.

    Yes, this is possible, but the name must be in the CSV file, otherwise it's not possible to obtain the keywords.

    Is it so that the checklist will never be completed, unless you put a check mark somewhere after the first field in  the line.

    Unless these keywords must be defined in the script?

     

    Here is the new findNameInCsv(f) handler:

    ----------

    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"})
        return b
        set n to tName & ","
        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
                set x to ""
                if not b then -- if b is true, skip the checkmark thing in the csv file 
                    -- add the check mark at beginning of this  line
                    set item i of o's csvText to "✔," & t & "," & weekNumber
                end if
                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 (not b)
            end if
        end repeat
        return false
    end findNameInCsv
    
  • by MattJayC,

    MattJayC MattJayC Jan 8, 2013 1:07 AM in response to Jacques Rioux
    Level 1 (5 points)
    Desktops
    Jan 8, 2013 1:07 AM in response to Jacques Rioux

    Not sure if I understood your reply.

     

    at the end of the week everything in the "BRAND_WKXX_PSD" folder should be checked off the sku checklist. (its normally about 100items.

     

    Then within the "BRAND_WKXX_PSD" there are secondary and more images to accompany the primary image. Its these additional images that are not in the csv checklist, but the begining 16 digits of the Sku are.

     

    So for secondary images etc, I would like to add the relevant keywords from the list but not add a checkmark. The checkmark is reserved for primary images, (those that match the sku list exactly).

     

    Hope that makes more sense.

  • by Jacques Rioux,

    Jacques Rioux Jacques Rioux Jan 10, 2013 10:20 AM in response to MattJayC
    Level 4 (3,408 points)
    Mac OS X
    Jan 10, 2013 10:20 AM in response to MattJayC

    Hi,

     

    Ok, so the full name of the secondary image is not in the CSV text, but  the first 16 characters of the name is in the CSV text.

     

     

    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 count o's csvText
    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 & "," & weekNumber
    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 (not b)
    end if
    end repeat
    return false
    end findNameInCsv
    

     

    Hoping that it works,

    If that does not work, start a new thread, because  I would not come over on the forum for a few months.

  • by MattJayC,

    MattJayC MattJayC Jan 11, 2013 1:02 AM in response to Jacques Rioux
    Level 1 (5 points)
    Desktops
    Jan 11, 2013 1:02 AM in response to Jacques Rioux

    The keywords, still get added to the normal names but nothing happening with those ending _2, _3. etc

     

    Not to important as it is doing the important thing of adding to the others and having the checklist.\

     

    Many Thanks for you all your help, made life a little easier for me!!!!

Previous Page 2