Use applescript to add items in a list to a text document

Posted:
in Genius Bar edited January 2014
So I am trying to use my Mac to help me make discharge summaries a little easier. I have written this applescript to generate a text file with the basic patient info at the top. The problem I am having is with the last section. I have defined the variable otherdiagnoses as a list whose items contain secondary diagnoses for which the patient was treated. When I use the variable in the "set text to" command, rather than display a list of the items in otherdiagnoses, it runs all the items together into one line. So rather than get the output: HTNCADDM, I want:



HTN

CAD

DM



I have pasted in part of the script below. But the question is actually rather simple. How do I add items from a list to the text document? I have tried a repeat loop, but each time I use the "set" command, it erases what has previously been added to the document. Apparently the "add" command expects a mathematical expression, and I am just a novice at read the dictionaries. Is there an "append" command I am missing somewhere?



-- Get Other Diagnoses

set adddiagnosis to {"", "another"}

set otherdiagnoses to {}

repeat while item 2 of adddiagnosis is "another"

\tdisplay dialog "other diagnosis" default answer "" buttons {"done", "another"} default button 2

\tset adddiagnosis to {the text returned of the result, the button returned of the result}

\tset the end of otherdiagnoses to item 1 of adddiagnosis

end repeat

-- End Get Other Diagnoses



-- Make the Textedit file

tell application "TextEdit"

\tmake new document at the front

\tset the text of the front document to "Discharge Summary" & "



" & item 1 of patientinfo & "

MR#" & item 2 of patientinfo & "

" & "Dates hospitalized " & item 3 of patientinfo & "

" & "DISCHARGE DIAGNOSIS" & "

" & item 4 of patientinfo & "



" & "OTHER DIAGNOSES" & "

" & otherdiagnoses

end tell

-- End Make the Textedit file

Comments

  • Reply 1 of 1
    If I remember correctly, you can insert a carriage return by simply inserting "& return".



    Eg:

    set item1 to "hello"

    set item2 to "goodbye"

    set item3 to item1 & return & item2
Sign In or Register to comment.