Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Where does the information get fed back to the main script?

I'm breaking down this script create by Jacques Rioux i've had to modifiy it so I can understand it.


I'm trying to find out where the information for this line gets fed from the handler.

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

-- *** 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 ***

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




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 suffix to text -(tc + 1) thru -tc of tName-- get last 3 characters before name extension--> _02

else -- no extension

set suffix to text -2 thru -1 of tName-- get last 3 characters --> _02

end if


tell suffix to set b to it starts with "_" and (text 2 is in "23456789")

try

if b then set sku_only 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 WholenameComma to tName & ","



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

if suffix begins with "_" then set WholenameComma to (text 1 thru 16 of tName & ".PSD,") -- the begining 16 digits, I presume the first 16 characters in the nameon error

set b to false



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



set tc to counto'scsvText

repeat with i from 1 to tc

set aRowinSkulist to itemi of o'scsvText



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


if not b and (aRowinSkulist starts with WholenameComma) or (aRowinSkulist starts with ("," & WholenameComma)) then -- found



(*set x to ""*)


--Not sure of its purpose



(*or b and (aRowinSkulist starts with WholenameComma or aRowinSkulist starts with "," & WholenameComma)*)


if not b then set item i of o's csvText to "," & aRowinSkulist

set text item delimiters to {","}

try

set headline2 to text item 2 of aRowinSkulist--get original Name

set x3 to (text item 3 of aRowinSkulist) & "ALTERNATIVE CODE :_" --get alternative Sku

set keyword4 to text item 4 of aRowinSkulist-- get the keyword

try

set WeekNumber5 to text item 6 of aRowinSkulist--get AIR OR SEA RECORD

on error

set WeekNumber5 to ""

end try

end try

set text item delimiters to tid


-- exiftool add the keywords to EXIF


if keyword4 is not "" then do shell script "/usr/bin/exiftool -P -overwrite_original_in_place -keywords+=" & (quoted form of keyword4) & " -headline=" & (quoted form of headline2) & " -source=" & (quoted form of WeekNumber5) & " " & quoted form of POSIX path of f


return (not b)


end if


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

end repeat


return false


end findNameInCsv

Mac Pro, OS X Mavericks (10.9)

Posted on Dec 1, 2013 9:32 AM

Reply
6 replies

Dec 1, 2013 10:06 AM in response to MattJayC

'm trying to find out where the information for this line gets fed from the handler.

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

-- *** find this name in CSV text ***

if existsCSV and (my findNameInCsv(bh_path)) then setisChanged to true-- a check mark was added in CSV text ***

Anywhere in the handler where this is a return statement is a potential place where the handler returns a result.


If that particular handler if it gets all the way to the end without returning anything it returns false

Dec 1, 2013 10:22 AM in response to Frank Caggiano

I added it at the bottom.

I think the tick might happen in the handler

write_to_file




Sorry this bit looks so huge,



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

tell application "Finder" to set CompletedFolder to folder (((path to pictures folder) as text) & "CompletedFolders")


try

tell application "Finder" to set bh_folders to (get every folder of CompletedFolder 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} to my getCSVpath(fName) -- get the CSV path and the week number

set existsCSV to checkListFile is not ""

if existsCSV then set o'scsvText to paragraphs of (readcheckListFileas «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}


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



-- *** 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

-----------------------CSV UPDATE HERE-----------------------------------------------------------

if isChanged then -- CSV file must be updated ***

set r to my write_to_file(checkListFile, o'scsvText) -- *** 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 6 -- ***

end if

set o'scsvText to {} -- empty this property to not save his contents when the script quit ***

end if

end if

end if

on error error_message


display dialogerror_messagebuttons {"OK"} default button 1

end try


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 home folder as string) & "Dropbox:" & "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 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 suffix to text -(tc + 1) thru -tc of tName-- get last 3 characters before name extension--> _02

else -- no extension

set suffix to text -2 thru -1 of tName-- get last 3 characters --> _02

end if


tell suffix to set b to it starts with "_" and (text 2 is in "23456789")

try

if b then set sku_only 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 WholenameComma to tName & ","



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

if suffix begins with "_" then set WholenameComma to (text 1 thru 16 of tName & ".PSD,") -- the begining 16 digits, I presume the first 16 characters in the nameon error

set b to false



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



set tc to counto'scsvText

repeat with i from 1 to tc

set aRowinSkulist to itemi of o'scsvText



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


if not b and (aRowinSkulist starts with WholenameComma) or (aRowinSkulist starts with ("," & WholenameComma)) then -- found



(*set x to ""*)


--Not sure of its purpose



(*or b and (aRowinSkulist starts with WholenameComma or aRowinSkulist starts with "," & WholenameComma)*)


if not b then set item i of o's csvText to "," & aRowinSkulist

set text item delimiters to {","}

try

set headline2 to text item 2 of aRowinSkulist--get original Name

set x3 to (text item 3 of aRowinSkulist) & "ALTERNATIVE CODE :_" --get alternative Sku

set keyword4 to text item 4 of aRowinSkulist-- get the keyword

try

set WeekNumber5 to text item 6 of aRowinSkulist--get AIR OR SEA RECORD

on error

set WeekNumber5 to ""

end try

end try

set text item delimiters to tid


-- exiftool add the keywords to EXIF


if keyword4 is not "" then do shell script "/usr/bin/exiftool -P -overwrite_original_in_place -keywords+=" & (quoted form of keyword4) & " -headline=" & (quoted form of headline2) & " -source=" & (quoted form of WeekNumber5) & " " & quoted form of POSIX path of f


return (not b)


end if


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

end repeat


-------------------added this part--------------------------------------------------------------------------- ----------------------------

if suffix starts with "_" then

return true

else

return false

end if


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 accessopenfile

on error

try


close accessthe_file

end try

end try

return n1 = n-- if the number of lines equal the numbers of check marks

end write_to_file

Dec 1, 2013 10:39 AM in response to MattJayC

MattJayC wrote:


Hmm, its what I thought


So I added


if suffix starts with "_" then

return true

else

return false

end if


But it still writes all the "," to the CSV file, I'm trying to get it to avoid doing this on all files that end in "_2" , " _3" etc.


If you don;t want it to write the file if the suffix starts with a underscore you should return false in that case as near as I can figure.


But honestly this code is very difficult to trace out and really needs to be rewritten.

Where does the information get fed back to the main script?

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