- Applescript: trim spaces and return line
- 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
- set theFile to (choose file)
- set theLines to paragraphs 28 thru -1 of (read theFile)
- repeat -- forever
- set someLine to some item of theLines
- -- trim characters at the start
- if someLine is not "" then repeat until the first character of someLine is not in {space, tab, quote}
- if (count someLine) is 1 then
- set someLine to ""
- exit repeat
- end if
- set someLine to text 2 thru -1 of someLine
- end repeat
- -- trim characters at the end
- if someLine is not "" then repeat until the last character of someLine is not in {quote}
- if (count someLine) is 1 then
- set someLine to ""
- exit repeat
- end if
- set someLine to text 1 thru -2 of someLine
- end repeat
- if someLine is not "" then exit repeat
- end repeat
- return someLine
- set the text item delimiters of AppleScript to return
- set AppleScript's text item delimiters to ""
- return text items 2 thru -2 of some_string
- 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_lines to (every paragraph of the_text)
- set this_line to some item of the_lines
- if this_line is not "" then
- set AppleScript's text item delimiters to ""
- set this_line to (text items 2 thru -2 of this_line) --remove the quotes
- set AppleScript's text item delimiters to space
- set these_items to (every text item of this_code)
- set the this_line to (item 1 of these_items & this_line)
- set AppleScript's text item delimiters to ""
- return this_line
- end if
- if paragraph i of some_text is not "" then do_something()
- on trimWhiteSpace(aString)
- if aString is not "" then
- -- setup for no delimiter
- set savedTextItemDelimiters to AppleScript's text item delimiters
- set AppleScript's text item delimiters to ""
- -- start with the tail end by revering the list
- set these_items to reverse of (every text item of aString)
- -- keep peeling off 1st space
- repeat while item 1 of these_items is space
- set these_items to rest of these_items
- end repeat
- -- flip the list, now do the leading characters
- set these_items to reverse of these_items
- repeat while item 1 of these_items is space
- set these_items to rest of these_items
- end repeat
- -- reconstruct the string
- set these_items to these_items as string
- -- restore and return
- set AppleScript's text item delimiters to savedTextItemDelimiters
- return these_items
- end if
- end trimWhiteSpace