set dialogResult to display dialog ¬
“What is your name?” buttons {“Cancel”, “OK”} ¬
default button “OK” cancel button ¬
“Cancel” giving up after 60 ¬
default answer " "
if button returned of dialogResult is “OK” then
say “hi”
say text returned of dialogResult
end if]
set dialogResult to display dialog ¬
“What is your name?” buttons {“Cancel”, “OK”} ¬
default button “OK” cancel button ¬
“Cancel” giving up after 60 ¬
default answer " "
if button returned of dialogResult is “OK” then
say “hi”
say text returned of dialogResult
end if
set dialogResult to display dialog ¬
"What is your name?" buttons {"Cancel", "OK"} ¬
default button "OK" cancel button ¬
"Cancel" giving up after 60 ¬
default answer " "
if button returned of dialogResult is "OK" then
say "hi"
say text returned of dialogResult
end if]
set dialogResult to display dialog ¬
"What is your name?" buttons {"Cancel", "OK"} ¬
default button "OK" cancel button ¬
"Cancel" giving up after 60 ¬
default answer " "
if button returned of dialogResult is "OK" then
say "hi"
say text returned of dialogResult
end if
In the header of the form for entering a message here you’ll see an AppleScript button. Select your script and click the button to make the script downloadable.
Instead of repeating a script, you might try using a repeat loop, and it’s a good idea to test for unexpected results:
repeat 2 times
set dialogResult to display dialog ¬
"What is your name?" buttons {"Cancel", "OK"} ¬
default button "OK" cancel button ¬
"Cancel" giving up after 60 ¬
default answer " "
if button returned of dialogResult is "OK" then
if text returned of dialogResult is " " then
say "No name?"
else
say "Oh, hi" & text returned of dialogResult
end if
end if
end repeat
thanks that helps a lot i have not learned how to use loops as of yet but i might looking to finding more about how they work. do u know any good sites that i should try?
Maybe you should check in a different way if the user has entered no name:
property ALPHABET_26 : "abcdefghijklmnopqrstuvwxyz"
StringIsEmpty(" ,#") --> true
StringIsEmpty("Jack Smith") --> false
StringIsEmpty(" ") --> true
StringIsEmpty("Ã ") --> true (maybe implement special characters?)
on StringIsEmpty(aString)
set characterIsInString to false
repeat with aChar in ALPHABET_26
if aString contains aChar then
set characterIsInString to true
exit repeat
end if
end repeat
return not characterIsInString
end StringIsEmpty
There are a lot of good tutorials here http://macscripter.net/viewforum.php?id=31 that show lots of ways to do things. You should start by reading through some of them.