Read text file: Delimiter (return): Find String

New to Applescript:
I’m trying to continuously check/read a text file until a specific value (specificValue) has been written to it. I’m using delimiter return to split into lines. I’d like to read the lines looking for the specific value.

I’m learning javascript and understand reading items into an array and going through the lines but am confused as to how Applescript does the same thing.

So far this is what I have:

set RCF_file to projectFolder & projName & "_RCF.txt" as string
set valueFound to false

repeat while valueFound is false
	tell application "Finder"
		set fileContents to (read RCF_file using delimiter return)
		if specificValue = "item2=(Finished,1,1,0)" then
			set valueFound to true
			close access fileContents
		end if
	end tell
end repeat

There’s some good tutorials on this website to help you learn here. I did the ones titled “Applescript tutorial for beginners”. This should get you started…

set RCF_file to (path to documents folder as text) & "projectFolder:projName:_RCF.txt"
set specificValue to "item2=(Finished,1,1,0)"

set fileContents to paragraphs of (read file RCF_file)

set valueFound to false
repeat with i from 1 to (count of fileContents)
	if (item i of fileContents) is equal to specificValue then
		set valueFound to true
		exit repeat
	end if
end repeat

if valueFound then
	-- do something
	display dialog "Could not find the specific value in the file."
end if

FYI: I like to use “paragraphs” to separate the text instead of the “return” as you did because “paragraphs” accounts for all the different possible line endings.

Thank you Hank-

I appreciate the help! I’m trying the script you posted now. Thank you for the learning resources also! I will definitely work my way through all the tutorials.

Shawn :slight_smile: