I wrote the following script to generate call reports. It launches TextEdit, adds a header and formats the text. The problem I’m having is that I get an error if TextEdit is already running. If it’s not running, it opens a doc on launch. How do I get it to open a new doc if it’s already running? Here’s what I have so far:
– Get timestamp, format it to the clipboard
set time_stamp to do shell script “date +%Y-%m-%d\ %H:%M:%S”
set date_header to "Date: " & time_stamp & return & "From: " & return & "Re: "
set the clipboard to the date_header
– Open TextEdit
tell application “TextEdit”
activate
– build header
set paragraph 1 of document 1 to date_header & return
set paragraph 2 of document 1 to "From: " & return
set paragraph 3 of document 1 to "Re: " & (return & return)
– format text
set plain_font to font of paragraph 1 of document 1
set i to 1
repeat 3 times
set font of paragraph i of document 1 to plain_font & “-Bold”
set i to i + 1
end repeat
end tell
Thanks Jon for cleaning up my script. I’ve just started learning Applescript and have learned more from having my stuff ripped apart here than from struggling thru the product documentation.
Kel - I like your launch suggestion as it doesn’t overwrite a document that might already be open. Muchas gracias amigo