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
http://s93769967.onlinehome.us/start.jpg
and convert it to a table in a applescript application looking something like this
http://s93769967.onlinehome.us/result.jpg
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)
try
set thisFile to thisFile as text
set thisFile to open for access file thisFile
set thisFile to "1
repeat
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
end repeat
stuff ’s rest
end getItems
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.