Hello all, another question I’m hoping you can help me with. I’m trying to read my preferences file, and then use the ol’ Applescript text item delimiters to parse out the values I need. Unfortunately, when I run my parsing function, it works great when I supply hard-coded text, but when I pass in the results of my file read, it can’t find anything (it always delimits as one item, no matter what string I set as the delimiters). I’ve attached my parsing function and my file reading function.
As a separate bonus item, how do you write returns into string literals? If I were coding C, I would use “\n”, but I don’t think that works here (although I guess I haven’t actually tried it ;-)).
Thanks for your assistance!
-Joe
-- returns the entire contents of the file with the given path
on ReadFile(filePath)
set fileRef to open for access filePath
set fileContents to (read fileRef)
close access fileRef
return (fileContents as string)
end ReadFile
-- searches theString for the value inbetween the beforeText and afterText
on getValueBetween(beforeText, afterText, theString)
set OldDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to beforeText
set textItems to text items of theString
set AppleScript's text item delimiters to OldDelims
if ((count of textItems) is 1) then return "" -- no beforeText
set AppleScript's text item delimiters to afterText
set textItems2 to text items of (second item of textItems)
set AppleScript's text item delimiters to OldDelims
if ((count of textItems2) is 1) then return "" -- no afterText after beforeText
return (first item of textItems2)
end getValueBetween