I’m working on a script that processes and converts word-processing files into a different format. When the script opens an old file from a DOS PC, and the file has no file type or creator code, I read the first paragraph of the file into a variable and display that variable to the user. This is the code I use to extract the first paragraph of the file:
set checkItem to choose file
my readfile(checkItem)
on readFile(checkItem)
set openCheckItem to (open for access checkItem)
set fileText to (read openCheckItem for (get eof openCheckItem))
close access openCheckItem
set paragraphList to every paragraph of fileText
set firstPara to first item in paragraphList
end readFile
In some files, the first few paragraphs are blank, and I want to display the first non-blank paragraph. I can’t figure out how to change this code so that it tests the first ten paragraphs, and displays the first non-blank one.
Could anyone kindly help me out with this? Thank you for any advice.