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"

3 Answers 3

2

simple solution

display dialog "Please Enter Your Name." default answer " " with title "Enter Name" buttons {"OK"} default button 1
Sign up to request clarification or add additional context in comments.

Comments

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

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.