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 openfilebh_path

copy the dimensions of bh_image to {xbhwidth, ybhheight}


closebh_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 dialogerror_messagebuttons {"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 openfileBurt_path

copy the dimensions of Burt_image to {xBurtwidth, yBurtheight}


closeBurt_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 dialogerror_messagebuttons {"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 offsetofthisCharin 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 ifthatispossible?


NOW Keywords i'll come back to that)


IfallthefileshaveaY or nextto 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

Reply
21 replies

Dec 20, 2012 12:56 AM in response to MattJayC

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

Dec 20, 2012 1:22 AM in response to MattJayC

WOW WOW WOW WOW


That worked wonderfully!


(almost)


the problems I had was it went looking for a CSV file named BH_WK18_PSD.CSV where is should be BH_WK18.CSV (I physically changed it to test out)


then when complete the label didn't turn green,

this is how it looked in the file. It might be i forgot to tell you about the , 18 (also referencing the week number)

although it did add in the tick!


BH70ER05215SV1SV.PSD,BH70ER05215SV1SV,,Triple Link Ring Earrings,18


Many Thanks, well impressed nonetheless!


Do you have a websoite that you can contacted on directly?


Matt

Dec 20, 2012 6:19 AM in response to MattJayC

Error from the Folder label bit, although no error


tell application "Finder"

get every folder of desktop whose name starts with "DVL"

--> {folder "DVL_WK19_PSD" of desktop}

get every file of folder "DVL_WK19_PSD" of desktop whose {"TIFF", "JPEG", "PNGf", "PICT"} contains file type or {"tif", "tiff", "jpg", "jpeg", "png", "pict", "psd"} contains name extension

--> {document file "DV25NW05863BK1GO.psd" of folder "DVL_WK19_PSD" of folder "Desktop" of folder "matthew" of folder "Users" of startup disk, document file "DV25WW04135GO1AG.psd" of folder "DVL_WK19_PSD" of folder "Desktop" of folder "matthew" of folder "Users" of startup disk, document file "DV25WW04200MU4MM.psd" of folder "DVL_WK19_PSD" of folder "Desktop" of folder "matthew" of folder "Users" of startup disk}

get name of folder "DVL_WK19_PSD" of desktop

--> "DVL_WK19_PSD"

get file "DVL_WK19_PSD.csv" of folder "keywords" of desktop

--> alias "Hal 9000:Users:matthew:Desktop:Keywords:DVL_WK19_PSD.csv"

end tell

tell current application

read alias "Hal 9000:Users:matthew:Desktop:Keywords:DVL_WK19_PSD.csv" as «class utf8»

--> "DV25WW04135GO1AG.PSD,DV25WW04135GO1AG,,Wing Cuff,19

DV25WW04200MU4MM.PSD,DV25WW04200MU4MM,,Mesh Cube Wristwear Pack ,19

DV25NW05863BK1GO.PSD,DV25NW05863BK1GO,,Dip Dye Spike Necklace,19

"

end tell

tell application "Image Events"


launch

end tell

tell application "Finder"

get document file "DV25NW05863BK1GO.psd" of folder "DVL_WK19_PSD" of folder "Desktop" of folder "matthew" of folder "Users" of startup disk

--> "Hal 9000:Users:matthew:Desktop:DVL_WK19_PSD:DV25NW05863BK1GO.psd"

end tell

tell application "Image Events"

open file "Hal 9000:Users:matthew:Desktop:DVL_WK19_PSD:DV25NW05863BK1GO.psd"

--> image "DV25NW05863BK1GO.psd"

get dimensions of image "DV25NW05863BK1GO.psd"

--> {3252, 4421}

close image "DV25NW05863BK1GO.psd"

end tell

tell application "Finder"

set label index of document file "Hal 9000:Users:matthew:Desktop:DVL_WK19_PSD:DV25NW05863BK1GO.psd" to 6


--> 6

end tell

tell current application

do shell script "/usr/bin/exiftool -P -overwrite_original_in_place -keywords+='Dip Dye Spike Necklace' '/Users/matthew/Desktop/DVL_WK19_PSD/DV25NW05863BK1GO.psd'"

--> " 1 image files updated"

end tell

tell application "Finder"

get document file "DV25WW04135GO1AG.psd" of folder "DVL_WK19_PSD" of folder "Desktop" of folder "matthew" of folder "Users" of startup disk

--> "Hal 9000:Users:matthew:Desktop:DVL_WK19_PSD:DV25WW04135GO1AG.psd"

end tell

tell application "Image Events"

open file "Hal 9000:Users:matthew:Desktop:DVL_WK19_PSD:DV25WW04135GO1AG.psd"

--> image "DV25WW04135GO1AG.psd"

get dimensions of image "DV25WW04135GO1AG.psd"

--> {1848, 2511}

close image "DV25WW04135GO1AG.psd"

end tell

tell application "Finder"

set label index of document file "Hal 9000:Users:matthew:Desktop:DVL_WK19_PSD:DV25WW04135GO1AG.psd" to 6


--> 6

end tell

tell current application

do shell script "/usr/bin/exiftool -P -overwrite_original_in_place -keywords+='Wing Cuff' '/Users/matthew/Desktop/DVL_WK19_PSD/DV25WW04135GO1AG.psd'"

--> " 1 image files updated"

end tell

tell application "Finder"

get document file "DV25WW04200MU4MM.psd" of folder "DVL_WK19_PSD" of folder "Desktop" of folder "matthew" of folder "Users" of startup disk

--> "Hal 9000:Users:matthew:Desktop:DVL_WK19_PSD:DV25WW04200MU4MM.psd"

end tell

tell application "Image Events"

open file "Hal 9000:Users:matthew:Desktop:DVL_WK19_PSD:DV25WW04200MU4MM.psd"

--> image "DV25WW04200MU4MM.psd"

get dimensions of image "DV25WW04200MU4MM.psd"

--> {2783, 3782}

close image "DV25WW04200MU4MM.psd"

end tell

tell application "Finder"

set label index of document file "Hal 9000:Users:matthew:Desktop:DVL_WK19_PSD:DV25WW04200MU4MM.psd" to 6


--> 6

end tell

tell current application

do shell script "/usr/bin/exiftool -P -overwrite_original_in_place -keywords+='Mesh Cube Wristwear Pack ' '/Users/matthew/Desktop/DVL_WK19_PSD/DV25WW04200MU4MM.psd'"

--> " 1 image files updated"

open for access alias "Hal 9000:Users:matthew:Desktop:Keywords:DVL_WK19_PSD.csv" with write permission

--> 155


set eof 155 to 0

write "DV25WW04135GO1AG.PSD,DV25WW04135GO1AG,,Wing Cuff,19,✔

DV25WW04200MU4MM.PSD,DV25WW04200MU4MM,,Mesh Cube Wristwear Pack ,19,✔

DV25NW05863BK1GO.PSD,DV25NW05863BK1GO,,Dip Dye Spike Necklace,19,✔

" to 155 starting at 0 as «class utf8»


close access 155

end tell

Dec 20, 2012 4:07 PM in response to MattJayC

Hi.


I'm glad it helps you.


MattJayC wrote:

the problems I had was it went looking for a CSV file named BH_WK18_PSD.CSV where is should be BH_WK18.CSV (I physically changed it to test out)


then when complete the label didn't turn green,

this is how it looked in the file. It might be i forgot to tell you about the , 18 (also referencing the week number)

although it did add in the tick!


OK,


Now :

To get the name of the CSV file, the script remove the last underscore and characters after it from the folder name

The script get the week number from the folder name.

The script check if exists the CSV file.

The script add the week number and the check mark to the end of the line --> ,18,✔


The folder label didn't turn green, because the last line in your CSV file was a blank line.

Now the script doesn't count the last line if the last line is empty.

If the CSV text contains more blank lines, a slight modification is required.


------

property type_list : {"TIFF", "JPEG", "PNGf", "PICT"}
property extension_list : {"tif", "tiff", "jpg", "jpeg", "png", "pict", "psd"}
property weekNumber : missing value
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 ***
          end tell
          
          if bh_files is not {} then -- ***
               set isChanged to false -- ***
               set {checkListFile, weekNumber} to my getCSVpath(fName) -- get the CSV path and the week number
               set existsCSV to checkListFile is not ""
               if existsCSV then 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 existsCSV and (my findNameInCsv(bh_path)) then set isChanged to true --  a check mark was added in CSV text ***
               end repeat
               if existsCSV then
                    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
     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 getCSVpath(fName) -- return the path of the CSV file, and the week number
     set {tid, text item delimiters} to {text item delimiters, {"_"}}
     set tName to text 1 thru text item -2 of fName -- remove  the last underscore and characters after it
     set text item delimiters to tid
     try
          set p to "" -- if not exists then the path will be empty
          set p to ((path to desktop folder as string) & "keywords:" & tName & ".csv") as alias 
     end try
     return {p, text -2 thru -1 of tName}
end getCSVpath

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 ""
                    -- add the week number and a check mark to the end of this  line
                    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 true
               end if
               return false -- exit the loop (the name was found).
          end if
     end repeat
     return false
end findNameInCsv



Make a script or edit a script is not very complicated for me, it does not take me much time.

If I have a little time to help, I come on this forum.

Dec 20, 2012 4:39 PM in response to Jacques Rioux

if the week number is less than ten and it is not padded with a zero, replace the handler getCSVpath(fName)

by this


on getCSVpath(fName) -- return the path of the CSV file, and the week number
     set {tid, text item delimiters} to {text item delimiters, {"_"}}
     set tName to text 1 thru text item -2 of fName -- remove  the last underscore and characters after it
     set text item delimiters to tid
     try
          set p to "" -- if not exists then the path will be empty
          set p to ((path to desktop folder as string) & "keywords:" & tName & ".csv") as alias 
     end try
     if character -2 of tName is in "1234567890" then
          set wn to text -2 thru -1 of tName
     else 
          set wn to last character of tName
     end
     return {p, wn}
end getCSVpath


("BH_WK1" or "BH_WK01") Whether one or the other, it will work without problem.

Jan 4, 2013 10:27 AM in response to MattJayC

MattJayC wrote:


Hi me again does it have to be in UTF-8? I assume this is show that it shows the tick correctly?


This character can not be encoded in Mac Roman, try it in TextEdit (plain text, not RTF), the list of encoding is limited when saving the doc.



MattJayC wrote:


Only I was wondering if I could change the line colour from the black to green, I was thinking of doing this so that I can see whats missing in the list?


Another method, would be to open the CSV file in Numbers or Excel, simply sort the last column.



MattJayC wrote:


But to do this it would need to be rich text?


Yes, this must be RTF or HTML.

If you want to use an RTF file, it is no longer possible in AppleScript without using an application to edit the RTF.


Here is the script that uses the application "TextEdit" to read and edit the RTF file:

--------------

property type_list : {"TIFF", "JPEG", "PNGf", "PICT"}
property extension_list : {"tif", "tiff", "jpg", "jpeg", "png", "pict", "psd"}
property weekNumber : missing value
property checkList_Doc : missing value
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 RTF file ***
        end tell
        
        if bh_files is not {} then -- ***
            set isChanged to false -- ***
            set {checkListFile, weekNumber} to my getCSVpath(fName) -- get the RTF path and the week number
            set existsCSV to checkListFile is not ""
            if existsCSV then tell application "TextEdit"
                open checkListFile -- open RTF file ***
                set checkList_Doc to front document
                set o's csvText to paragraphs of (get text of checkList_Doc)
            end tell
            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 RTF text ***
                if existsCSV and (my findNameInCsv(bh_path)) then set isChanged to true --  a check mark was added in RTF text ***
            end repeat
            if existsCSV then
                if isChanged then -- RTF file must be updated ***
                    set {tid, text item delimiters} to {text item delimiters, {"✔"}}
                    set n to (count text items of o's csvText) - 1 -- count check mark
                    set text item delimiters to tid
                    set n1 to (count o's csvText) -- count lines
                    if last item of o's csvText is "" then set n1 to n1 - 1 -- last line is blank
                    
                    -- *** save RTF file ***
                    tell application "TextEdit" to tell checkList_Doc
                        save
                        close
                    end tell
                    
                    -- *** if n = n1, the checkList is complete so change the folder label to green ***
                    if n = n1 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
    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 getCSVpath(fName) -- return the path of the RTF file, and the week number
    set {tid, text item delimiters} to {text item delimiters, {"_"}}
    set tName to text 1 thru text item -2 of fName -- remove  the last underscore and characters after it
    set text item delimiters to tid
    try
        set p to "" -- if not exists then the path will be empty
        set p to ((path to desktop folder as string) & "keywords:" & tName & ".rtf") as alias
    end try
    if character -2 of tName is in "1234567890" then
        set wn to text -2 thru -1 of tName
    else
        set wn to last character of tName
    end if
    return {p, wn}
end getCSVpath

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 ""
                -- add the week number and a check mark to the end of this  line
                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
                
                -- *** add text in line of the RTF doc and change the line color
                tell application "TextEdit"
                    tell paragraph i of checkList_Doc
                        set character -2 to character -2 & "," & weekNumber & ",✔"
                        set color of it to {27530, 37067, 24918}
                    end tell
                end tell
                
                --  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

Jan 5, 2013 12:49 AM in response to Jacques Rioux

That did work well, but as this script is running ifrom the launchDeamons it means of course that textedit is opening and closing so would no doubt slow me down. Not tried it yet fully working but I assume that could be the case?


Might opt to put the tick at the start of the line as that might make it easier to see those that don't. that was a nice script as textedit doesn't even open!


I'll give the above a try as it could work, i just like the least use of programmes, in particular the likes of excel. (sadly don't have numbers (cheap I know but its a work computer)

Jan 5, 2013 9:18 AM in response to MattJayC

MattJayC wrote:


I'll give the above a try as it could work, i just like the least use of programmes, in particular the likes of excel. (sadly don't have numbers (cheap I know but its a work computer)


The best would be to use one or both of these modified handlers rather than using a RTF file.


1- If you want lines without check mark at the top:

Replace the write_to_file(the_file, tList) handler by this

------------

on write_to_file(the_file, tList) -- update CSV file ***
    set n to 0
    set n1 to 0
    set tc to count o's csvText
    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 item i of o's csvText 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's csvText) as text -- convert list of lines to text
    set text item delimiters to tid
    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
    return n1 = n -- if the number of lines equal the numbers of check marks
end write_to_file




2- If you want the check mark at the beginning of the line:

Replace the findNameInCsv(f) handler by this

------

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
            set x to ""
            -- add the check mark at beginning of this  line
            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 true
        end if
    end repeat
    return false
end findNameInCsv

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Image checklist and add keywords

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.