I realize that this question has most likely been asked in the past, but a search on these forums and googling for the last 2 days has been futile.
I am trying to take a text file with odd formating, looking like this
and convert it to a table in a applescript application looking something like this
So far my attempts have failed due to my inexperience using Applescript. The problem I’m having is highlighted here in my code
on parseStories(thisFile, theDataSource)
set thisFile to thisFile as text
set thisFile to open for access file thisFile
set thisFile to "1
read thisFile before “<”
set currentTag to read thisFile until “>”
I cannot declare the file for input and pass it to this function.
Anyone have ideas?
You may want a routine similar to this one:
set fContents to “as1Man eaten by shark2Headline 2”
set ids to getItems(“”, “”, fContents)
set headlines to getItems(“”, “”, fContents)
to getItems( startTag, endTag, txt)
set prevTids to AppleScript’s text item delimiters
set AppleScript’s text item delimiters to startTag
set stuff to txt’s text items
set AppleScript’s text item delimiters to prevTids
repeat with i from 2 to count stuff
set stuff’s item i to text 1 thru ((offset of endTag in stuff’s item i) - 1) of stuff’s item i
Or, perhaps, you want take a look to
XML Tools, which is very useful to parse XML data (if you are doing so).
To read the file, simply:
set fContents to read alias "path:to:file"
Awesome stuff jj, I will download those xml tools and check them out.
The code you just made is very slick also and I believe I can implement that quickly.