This is how I am doing trying to cut down a script to make it work.(obviously its still not working.
Help most welcome please.
Matt
set EAN to text returned of (display dialog "SCAN" default answer "")
set csvText to (choose file with prompt "Open CSV CHECKLIST" as string)
logcsvText
if EAN is not {} then -- ***
set isChanged to false -- ***
set {checkListFile} to csvText-- get the CSV path and the week number
set existsCSV to checkListFile is not ""
if existsCSV then set o's csvText to paragraphs of (readcheckListFileas «class utf8») -- get the contents of the CSV file ***
-- *** find this name in CSV text ***
if existsCSV and (my findNameInCsv(csvText)) then set isChanged to true-- a
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 ***
set o's csvText to {} -- empty this property to not save his contents when the script quit ***
end if
end if
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
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
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
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 itemi 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 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