I need a dialog box that can accept input with OK and Cancel buttons (and buttons to act as “default” and “cancel”). I need to be able to detect the text input or the CANCEL or blank input. I dont know why I am having so much trouble with this (I can’t detect the cancel, blank part):
Set Answer to display dialog “Enter something” buttons {“Cancel”,“OK”} default button “OK”
Cancel button “Cancel” default answer “”
If Button returned of Answer is “OK” then
display dialog “1”
set TextReturned to text returned of result
Else
display dialog “2”
End if
If TextReturned of result is not “” then
.
.
.
End if
Hi Jack,
try something like this, pressing the Cancel button causes an error number -128
try
set Answer to display dialog "Enter something" buttons {"Cancel", "OK"} default button 2 default answer ""
set theText to text returned of Answer
if theText is "" then error number -128
display dialog theText
on error number n
if n = -128 then
display dialog "blank"
end if
end try
Note: the parameter Cancel button is only needed, if the name of the button is different.
The default name is “Cancel”
Just a variant of the StepanK response
try
set Answer to display dialog "Enter something" buttons {"Cancel", "OK"} default button 2 default answer ""
set theText to text returned of Answer
if theText is "" then (*
Here a blank response is treated as Cancel
but you may do what you want *)
error number -128
else
display dialog theText
end if
on error number n
if n = -128 then
display dialog "blank"
end if
end try
Yvan KOENIG (from FRANCE mercredi 13 août 2008 17:16:04)
Thanks guys. I’ll try these tonight when I get home.
Thanks again guys. Worked great
Alternatively:
display dialog "Enter something" default answer ""
set theText to text returned of result