Hi there is a thing I would like to do, I want to search for a string in a text edit file (.txt) without opening it and display a message if the string can’t be found. Is it something I can do?
set theFile to choose file of type {"public.plain-text"}
set fileContents to read theFile as «class utf8»
set theKeys to {"DESIGN PGM PRESS", "DGN 25635 PGM 25149 996 UV", "DGN 64636 PGM 69458 XL 105"}
set missing to {}
repeat with akey in theKeys
if fileContents does not contain akey then set end of missing to (akey as text) # Don't remove the late coercion
end repeat
set cnt to count missing
if cnt > 0 then
set msg to my recolle(missing, linefeed)
if cnt > 1 then
set msg to "the keys" & linefeed & msg & linefeed & "are missing"
else
set msg to "the key" & linefeed & msg & linefeed & "is missing"
end if
display dialog msg
end if
#=====
on recolle(l, d)
local oTIDs, t
set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d}
set t to l as text
set AppleScript's text item delimiters to oTIDs
return t
end recolle
#=====
Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) lundi 28 octobre 2019 12:21:19