display dialog help

In my script I would like the user to be able to enter text when prompted, and keep entering text until he clicks “Done” or some button like that. I know you can get text returned from a display dialog or you can get the button returned from a display dialog. Is there any way to combine the two? Thank you for any help.

The ‘display dialog’ command returns a record, containing both pieces of information:


set userInput to display dialog "Hi" buttons {"1", "2"} default answer "Type Here"

button returned of userInput --> "1" or "2"

text returned of userInput --> "Whatever was typed"

The record will also have a ‘gave up’ property, set to true or false, if the call to ‘display dialog’ included the ‘giving up after (number of seconds)’ parameter:


set userInput to display dialog "Hello" buttons {"Click Quickly"} giving up after 1

button returned of userInput --> ""

gave up of userInput --> true

You can always see what a command returns by making it the last executing statement in your script and examining the result in your Script Editor’s results window:


display dialog ("Prompt") ¬
	default answer ("Default Answer") ¬
	buttons ({"One", "Two", "Three"}) ¬
	default button ("One") ¬
	with icon (caution) ¬
	giving up after (60 * 60 * 24)
--
--> { text returned : "Default Answer", button returned : "One", gave up : false }

cool, thank you very much. Thismakes my script a lot better

or you could do it all in one line

set stuff to text returned of (display dialog "Types something cool!" default answer "" buttons{"Done"} default button 1)

then stuff will be whatever they typed