need help with scripting

ok, i just started learning applescript today and to kind of get a feel for the language i’m trying to make a simple script. what happens is a prompt comes up asking you to type some text. once the ok button is pressed textedit opens up and a new document is created and the text you typed in the prompt is placed in the document.
help would be appreciated:D

Greetings from another noob.

This will get you started:


set theText to text returned of (display dialog "Enter text" default answer "")--opens a dialog box with an empty text field, sets the text entered to variable theText - won't work without a default answer

tell application "TextEdit"
	activate--opens TextEdit
	make new document at the front--make new document frontmost so theText goes to the right place
	set the text of the front document to theText--puts theText into the document
end tell

Have fun.

j

edited for typos - I’m all thumbs on a keyboard

Hi guys.

There are a couple of small refinements to this kind of thing that you might like to play with.

If you hit the return key when entering text into a regular dialog, the effect is the same as if you’d pressed the enter key (or clicked the default button). In other words, because any of these actions will dismiss the dialog, you can’t enter paragraphs. However, if you wanted to enter paragraphs, then simply include a return character (or, for a larger entry area, several return characters) in the default answer:

display dialog "When done, press 'return' or 'enter' - or click 'OK'" default answer ""

display dialog "To add a new paragraph press 'return'. When done, press 'enter' - or click 'OK'" default answer return

display dialog "Here's an even larger entry area:" default answer return & return & return & return

When making a new application object (such as a TextEdit document, for example), you can sometimes set certain properties simultaneously:

set theText to text returned of (display dialog "Enter text" default answer return)
tell application "TextEdit"
	activate
	make new document with properties {text:theText}
end tell

I was wondering how to make the entry field larger, and it never occurred to me that paragraphs were possible. Thanks.

j

My pleasure, j. For more fun and games, you might like to check out the topic: A single dialog to handle multiple entries.

Thanks, I will.

j

ahh, thanks kai:D i logged on cuz i was just aboput to ask to to extend prompt boxes:P looks like you beat me to it!:smiley:

Remember, however, that to make multi-line entries, the user must use the down arrow (or mouse) to move the text cursor - the return and enter key will still dismiss the dialog whether it has a default button specified or not because dialogs default to the right-most button if not specified.

Um… not here, Adam (none of the above). What gives? :confused:

Um :o; I spoke (figuratively) without actually testing, Kai, after noting that the “OK” button was highlighted and assuming it was active. Sorry to confuse. :confused: Doh