Writing formatted text (Bold, center, e.t.c)

Hi.

I’m trying to make a form, where the user fills in all the details, and then it’s all saved to a text file. I have got the basic function to work, but the whole idea was that I format the text nicely for the user, to make it look nice and presentable. Basically, what I want to do is be able to have paragraphs, bold, font, text colour and text size applied to the contents of the text boxes. Here is what I have so far:


on clicked theObject
	if name of theObject = "write" then
		set yourname to contents of text field "yourname" of window "WriteMe"
		set thedate to contents of text field "thedate" of window "WriteMe"
		set f to ((choose folder) as text) & "Bio - Created by WriteMe.txt"
		set nref to open for access file f with write permission
		close access nref
		tell application "TextEdit"
			{on styles:{center, italic}}
			write (yourname & thedate) to file f
		end tell
	end if
end clicked

This works, but not quite, as it doesn’t actually do any of the formatting, but it just writes the name and date on the same line in a simple text file. Like I said, I want to have different colours, alignment, bold, font e.t.c. If anyone could do it, an added bonus would be writing some text as a hyperlink, but that’s not so important.

Anything you can contribute would be much appreciated. :slight_smile:

Thanks.

Model: ibook G4
AppleScript: 1.10.3
Browser: Safari 417.8
Operating System: Mac OS X (10.4)

I think the best and simplest option would be writing HTML (instead of regular text). This way you can format the text pretty easilly and display it in whatever place (including a web-view in your Studio app, TextEdit, Safari…).

It had crossed my mind. It isn’t perfect, but if the almighty JJ can’t think of a better way, then it must be the only way.

Thank you

If you need it so bad, there are other ways. That may depend on various factors: do you consider “smart” for your project launching a third-party application to format the text? I’m not sure, but I think there are some obj-c hooks to format text inside a textview, which you could save to a rtf file (jobu maybe here your man).

I think (again, not sure) you could also create a template rtf file, where you could insert later random data (text from input). For example, this could be a “template”:

Where you see the capitals, you can insert the input data, and you will end with a .rtf formatted file (“HERE GOES THE TITLE!!!” will be red-bold-centered text; “SOME TEXT HERE!!!” is regular “un-formatted” text; and where you see “HERE GOES THE LINK!!!”, TextEdit will display a link pointing to Google).

Wow! I’ll certainly have a play with that. You’re very helpful. Thank you.

Hi Lambo,

Also, TextEdit is not very scriptable. It has font, color, and size only. You could use the highly scriptable and versatile Tex-Edit Plus:

http://www.tex-edit.com/

gl,