This is my first post after browsing this great forum for awhile. Hello, all
I’m sort of in a “trial by fire” situation for learning Applescript and I have a situation that requires some advice.
I’m trying to create an Excel spreadsheet by extracting certain values from multiple text files.
This is the sample text file:
Editor: John Doe
Assign date: 12/13/07
Run date: 12/15/07
Publish size: 1 column
Department: Metro
With a script, I would like to isolate the information after each colon to make it easier to plug into cells within Excel. Is the best way to identify and remove the values of Editor: space, Assign date: space, etc. and save each file as a CSV?
set theText to "Editor: John Doe
Assign date: 12/13/07
Run date: 12/15/07
Publish size: 1 column
Department: Metro"
set newText to {}
set {TID, text item delimiters} to {text item delimiters, ": "}
repeat with oneLine in (get paragraphs of theText)
set end of newText to text item 2 of oneLine
end repeat
set text item delimiters to ", "
set newText to (newText as text) & return
set text item delimiters to TID
newText --> "John Doe, 12/13/07, 12/15/07, 1 column, Metro\r"
choose file without invisibles
read result using delimiter ": "
(*
{"Editor", " John Doe
Assign date", " 12/13/07
Run date", " 12/15/07
Publish size", " 1 column
Department", " Metro"}
*)
This should account for that:
choose file without invisibles
read result using delimiter {": ", (return & (ASCII character 10)), ASCII character 10, return}
-- {"Editor", " John Doe", "Assign date", " 12/13/07", "Run date", " 12/15/07", "Publish size", " 1 column", "Department", " Metro"}
Edit: Alternatively:
choose file without invisibles
read result using delimiter {": ", (return & (ASCII character 10)), ASCII character 10, return}
set example to item 2 of separateList(result)
--> {" John Doe", " 12/13/07", " 12/15/07", " 1 column", " Metro"}
on separateList(someList)
set output to {{}, {}}
repeat with i from 1 to count someList
set end of item (((i + 1) mod 2) + 1) of output to item i of someList
end repeat
return output
end separateList