I wrote an AppleScript that returns a random string from a text file delineated by commas:
set some_file to "Macintosh HD:Users:Zade:Library:Application Support:Notational Data:Words.txt" as alias
set the_text to read some_file as string
set the text item delimiters of AppleScript to ", "
set the_lines to (every text item of the_text)
return some item of the_lines
But I now have a text file delineated by new lines instead of commas. And each line begins with anywhere from 0-20 spaces. I want to return just the text portion of a random line. How do I do this?
Also, if the text portion is surrounded by plain (not curly) quotes, how can I trim the quotes?
Change the comma and space in the line
set the text item delimiters of AppleScript to ", "
toreturn
. The new line (no pun intended) looks like this:As for your second question try this:
Let's put it all together!
EDIT: You can't stop the program from returning empty lines, but you can filter them out like so...
The following script will handle the additional requirements from your comments, and includes statements to trim characters from the beginning and ending of the string. It excludes the first 27 lines read from the file and will repeatedly get and trim random lines from the list until the final result is not empty.
Here is what I use to trim spaces from both ends of a string