display dialog "Play game?" buttons {"Yes", "No"} with title "Play?"
if {button returned:"No"}
end if
I pressed compile to pretest and this happened:
Applescript error
Can’t make {button returned:"No"} into type boolean.
Try:
set buttonChoice to (display dialog "Play game?" buttons {"Yes", "No"} with title "Play?")
if button returned of buttonChoice = "No" then
return "no"
end if
Related
The Applescript results are Display "end tell"
I don't know why this is happening and need it fixed.
When I click next page for the second time, it "end tell"s randomly
This is the script:
display dialog "What would you like to launch? choose wisely!" buttons
{"Next Page", "cancel", "Google Chrome"} default button "Next Page"
if result = {button returned:"Google Chrome"} then
tell application "Google Chrome" to activate
else if result = {button returned:"cancel"} then
else if result = {button returned:"Next Page"} then
display dialog "Page 2" buttons {"Next page", "Mari0", "Minecraft"} default button "Next page"
if result = {button returned:"Minecraft"} then
tell application "Minecraft" to activate
else if result = {button returned:"Mari0"} then
tell application "Terminal"
activate
do script with command "open /Users/_________/Desktop/Mari0.app/"
delay 1
quit
end tell
else if return = {button returned:"Next page"} then
display dialog "Page 3" buttons {"Safari", "Roblox", "Next Page"} default button "Next Page"
if result = {button returned:"Roblox"} then
tell application "Google Chrome" to open location "http://www.roblox.com/home"
else if result = {button returned:"Safari"} then
tell application "Safari" to activate
else if return = {button returned:"Next Page"} then
display dialog "Final Page" buttons {"iMessages", "Applescript Folder", "Back to Start"} default button "Back to start"
if return = {button returned:"Back to start"} then
run script (open applications)
else if return = {button returned:"iMessages"} then
tell application "Messages" to activate
else if return = {button returned:"Applescript Folder"} then
do shell script "open /Users/__________/Desktop/Applescript/"
end if
end if
end if
end if
These are the results from the script:
tell application "Script Editor"
display dialog "What would you like to launch? choose wisely!"
buttons {"Next Page", "cancel", "Google Chrome"} default button "Next
Page"
--> {button returned:"Next Page"}
display dialog "Page 2"
buttons {"Next page", "Mari0", "Minecraft"} default button "Next page"
--> {button returned:"Next page"}
End tell
Since you are running this test in Script editor you are telling Script Editor to run it. Naturally the tell block ends with end tell. The script has ended and Script Editor is done with its job.
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"
simple solution
display dialog "Please Enter Your Name." default answer " " with title "Enter Name" buttons {"OK"} default button 1
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
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
I am working on the same app that I mentioned in my first question. I have gotten much farther, but when I try to play "2048" the first time, AppleScript give me the error:
"The variable result is not defined"
I will skip the main bulky body of the app and get to the area with the problem:
display dialog "What would you like to do?
Sleep = Go to sleep
Finder = Open Finder
Time = Display current time and date
2048 = play 2048
Quit = Quit application" default answer "" with title "Control panel"
if the text returned of the result is "Sleep" then
tell application "System Events" to sleep
display dialog "Hello, welcome back!" buttons {"Thank you!"} default button 1
return
else if the text returned of the result is "Finder" then
tell application "Finder" to make new Finder window
else if the text returned of the result is "Time" then
set a to (current date) as list
set AppleScript's text item delimiters to linefeed
set a to a as text
display dialog a buttons {"OK"} default button 1
else if the text returned of the result is "Quit" then
return
else if the text returned of the result is "2048" then
tell application "Terminal"
do script "/Users/student/Documents/2048.sh"
activate
end tell
else
display dialog "Invalid response" with title "Invalid response" buttons {"Go back", "Quit"} default button 1
end if
if the button returned of the result is "Go back" then
display dialog "What would you like to do?
Sleep = Go to sleep
Finder = Open Finder
Time = Display current time and date
2048 = play 2048
Quit = Quit application" default answer "" with title "Control panel"
else
return
end if
if the text returned of the result is "Sleep" then
tell application "System Events" to sleep
display dialog "Hello, welcome back!" buttons {"Thank you!"} default button 1
return
else if the text returned of the result is "Finder" then
tell application "Finder" to make new Finder window
else if the text returned of the result is "Time" then
set a to (current date) as list
set AppleScript's text item delimiters to linefeed
set a to a as text
display dialog a buttons {"OK"} default button 1
else if the text returned of the result is "Quit" then
return
else if the text returned of the result is "2048" then
tell application "Terminal"
do script "/Users/student/Documents/2048.sh"
activate
end tell
end if
Just set the result of the display dialog to a variable and use the variable. It's tricky to use "result" as you have in many if statements. One of them is bound to cause a problem because "result" will change at some point.
So do something like this right after your display dialog statement...
set {buttonReturned, textReturned} to {button returned of result, text returned of result}
Then in your if statements use buttonReturned or textReturned.
No matter what my password is, it always says my password isn't right! Help please. Here is the script
set my_password to display dialog ¬
"Please enter your password:" with title ¬
"Password" with icon stop ¬
default answer ¬
"" buttons {"Cancel", "OK"} default button 2 ¬
with hidden answer
if (text returned of my_password) is no then
display dialog "Running the application!" buttons ["OK"] default button 1
else if (text returned of my_password) is not no then
display dialog "Did not enter correct password!" buttons ["OK"] default button 1
end if
You must put the password (no) in quotes.
I also shortened the script. Try it out:
display dialog "Please enter your password:" with title "Password" with icon stop default answer "" buttons {"Cancel", "OK"} default button 2 with hidden answer
if (text returned of result) is "no" then
display dialog "Running the application!" buttons ["OK"] default button 1
else
display dialog "Did not enter correct password!" buttons ["OK"] default button 1
end if
I am having an error in AppleScript when I use less than or greater than operators consecutively. I probably didn't explain that very well, so I will post the code.
**set good to false**
**repeat until good = true**
set oneTen to the text returned of (display dialog "Pick a number from 1 through 10" default answer "" buttons {"OK"} default button 1) as number
if oneTen is less than 0 then
display dialog "below" buttons {""} default button 1
else if oneTen is greater than 10 then
display dialog "above" buttons {""} default button 1
else
set good to true
end if
**end repeat**
I am trying to take the input from the prompt, and keep the user from entering anything below 0 or above 10. Could you post some code to do this well?
I want something similar to this.
**set oneTen to the text returned of (display dialog "Pick a number from 1 through 10" default answer "" buttons {"OK"} default button 1) as number**
**if oneTen is less than 0 or greater than 10 then**
**-- make them do the prompt again**
**end if**
Try:
repeat
set oneTen to the text returned of (display dialog "Pick a number from 1 through 10" default answer "" buttons {"OK"} default button 1) as number
if oneTen is less than 0 then
display dialog "below" buttons {""} default button 1
else if oneTen is greater than 10 then
display dialog "above" buttons {""} default button 1
else
exit repeat
end if
end repeat