2

I'm running an applescript program where I am asking for the user to type in their name. If the user clicks "OK", then the name gets stored to the variable I want. However, if the user clicks "Cancel", then the program just quits. How do I set this up to either hide the "Cancel" button, so it's not an option to click, or to set up a loop so that if cancel is clicked, it just continues to ask the user for his/her name until it's entered?

Thanks in advance.

display dialog "Please Enter Your Name." default answer " " with title "Enter Name"
John
  • 21
  • 1
  • 2

3 Answers3

2

simple solution

display dialog "Please Enter Your Name." default answer " " with title "Enter Name" buttons {"OK"} default button 1
vadian
  • 274,689
  • 30
  • 353
  • 361
1

The way that you hide the cancel button is like this:

display dialog "Please Enter Your Name." default answer " " buttons {"ok"} with title "Enter Name"
set a to the text returned of the result

But if you wanted the repeat then use this (I have made it so they have to enter something too instead of just pressing ok to end it:

repeat
 display dialog "Please Enter Your Name." default answer "" buttons {"ok", "cancel"} default button 1 with title "Enter Name"
set a to the text returned of the result
if the button returned of a is "ok" then
    if the text returned of a ≠ "" then
        exit repeat
    end if
 end if
end repeat
0

Here's what I got:

display dialog "Please Enter Your Name." default answer "" buttons {"Submit"} with title "Enter Name" default button 1
    if the button returned of the result is "Submit" then
        set yourVariable to text returned of the result
    end if
Collin Alpert
  • 475
  • 6
  • 14