scripting Dashcode to make new doc with text…

Here’s an applescript that I’m going to use for taking notes on my laptop in school.

set this_moment to (the current date)
    set the_weekday to ((weekday of date (date string of (the current date))) as string)
    set the_month to ((month of date (date string of (the current date))) as string)
    set the_year to ((year of date (date string of (the current date))) as string)
    set the_day to ((day of date (date string of (the current date))) as string)
    tell application "TextEdit"
       make new document
       set {text of document 1, font of document 1, size of document 1} to {the_weekday & ", " & the_month & " " & the_day & ", " & the_year & return & " Solomon Freilich" & return & " <teacher's name (I make a script specific to each)>" & return & " <Science/subject that that teacher teaches>" & return & return, "Helvetica", "39.5"}
       set bounds of window 1 to {0, 22, 1280, 796}
    end tell

The above script snippet works fine.

I sometimes use html for notes and I like that when editing html in dashcode, you can press enter for a new a line & the browser will understand when your done as you’ll open it in your browser (I use Camino for html docs) and your line breaks will be there (unlike in TextEdit) where I find I have to write

, which gets tedious (as well as not visually easy while reading from the code, unless you press return too”which is just another keypress.

So I was thinking, "Great! I’ll replace the word ‘TextEdit’ with the word ‘Dashcode’ and replace the word ‘text’ with the word ‘rich text’ and all work the same (except in Dashcode instead of in TextEdit).

But it didn’t: Apple Event handler got an error of some kind & it seemed to be related to the ‘make new document’ part of the script. I compared TextEdit’s and Dashcode’s dictionaries & they are too similar for this thing to be happening.

Model: MacBook
Browser: Firefox 3.0.1
Operating System: Mac OS X (10.5)

Hi.

I don’t have Dashcode, so the following are just things to try. With some applications (early versions of TextEdit, for example), you have to specify where the new document’s created. This is just a formality to avoid an error; the new document usually appears in front of any others regardless of where you specify its creation:

tell application "TextEdit"
	make new document at beginning of documents

	-- Or you may get away with just:
	make new document at beginning
end tell

‘font’ and ‘size’ are usually properties of a document’s text rather than of the document itself.

tell application "TextEdit"
	set {text of document 1, font of text of document 1, size of text of document 1} to . etc.
end tell

With regard to your date parsing:

This is very laboured: 5 calls of the ‘current date’ function (the first result not used), 4 extractions of date strings, and 4 rederivations of the original dates (except for the times) from the date strings. It’s only necessary (and only desirable) to call ‘current date’ once. The properties you want can all be extracted directly from the result:

set this_moment to (the current date)
set the_weekday to ((weekday of this_moment) as string)
set the_month to ((month of this_moment) as string)
set the_year to ((year of this_moment) as string)
set the_day to ((day of this_moment) as string)

However, it’s also possible that on your computer, the ‘date string’ is exactly what you want to put into your document anyway:

set this_moment to (the current date)
set date_text to date string of this_moment
tell application "TextEdit"
	make new document at beginning
	set {text of document 1, font of text of document 1, size of text of document 1} to {date_text & return & " Solomon Freilich" & return & " <teacher's name (I make a script specific to each)>" & return & " <Science/subject that that teacher teaches>" & return & return, "Helvetica", "39.5"}
	set bounds of window 1 to {0, 22, 1280, 796}
end tell

Hope this helps.