Can someone tell me why this won't work? I can't for the life of me figure out why it doesn't. It compiles fine, looks fine, and this method has worked everywhere else for me... Really need some help, anyone know what's wrong?
set areatype to (choose from list {"Triagles", "Trapeziums"} with prompt "What would you like to calculate the area of?" with title "Area Calculator")
if areatype contains "Triangles" then
set height to text returned of (display dialog "What is the height of the triangle?" with title "Area Calculator" default answer "")
set base to text returned of (display dialog "What is the base of the triangle?" with title "Area Calculator" default answer "")
set area to (height * base) / 2
display dialog "Area = " & area & " units squared" with title "Area Calculator" buttons {"Cancel", "Go again"}
else
if areatype contains "Trapezium" then
set base1 to text returned of (display dialog "What is one base of the trapezium?" with title "Area Calculator" default answer "")
set base2 to text returned of (display dialog "What is the other base of the trapezium?" with title "Area Calculator" default answer "")
set area to ((a + b) / 2) * h
display dialog "Area = " & area & " units squared" with title "Area Calculator" buttons {"Cancel", "Go again"}
end if
end if
-Thanks
Look at your very first line in the code. You spelled Triangles incorrectly and you needed the "s" in Trapeziums added to the "else" line in the code.
on goAgain()
set areatype to (choose from list {"Triangles", "Trapeziums"} with prompt "What would you like to calculate the area of?" with title "Area Calculator")
if areatype contains "Triangles" then
set height to text returned of (display dialog "What is the height of the triangle?" with title "Area Calculator" default answer "")
set base to text returned of (display dialog "What is the base of the triangle?" with title "Area Calculator" default answer "")
set area to (height * base) / 2
display dialog "Area = " & area & " units squared" with title "Area Calculator" buttons {"Cancel", "Go again"}
if the button returned of the result is "Go again" then
goAgain()
else
return
end if
else
if areatype contains "Trapeziums" then
set base1 to text returned of (display dialog "What is one base of the trapezium?" with title "Area Calculator" default answer "")
set base2 to text returned of (display dialog "What is the other base of the trapezium?" with title "Area Calculator" default answer "")
set height2 to text returned of (display dialog "What is the height of the trapezium?" with title "Area Calculator" default answer "")
set area to ((base1 + base2) / 2) * height2
display dialog "Area = " & area & " units squared" with title "Area Calculator" buttons {"Cancel", "Go again"}
if the button returned of the result is "Go again" then
goAgain()
else
return
end if
end if
end if
end goAgain
goAgain()
Related
I have been working on a "notification previewer" applet for a while and I wanted to try and save notification data when the process is done.
When I added the .plist snippet of code into it I get an error that says "Cant get property list file in /~/~/~/~/~/~" (the random number at the end is a randomly generated number for the .plist).
Here is the code. Can anybody help me figure out whats wrong?
on getTimeInHoursAndMinutes()
-- Get the "hour"
set timeStr to time string of (current date)
set Pos to offset of ":" in timeStr
set theHour to characters 1 thru (Pos - 1) of timeStr as string
set timeStr to characters (Pos + 1) through end of timeStr as string
-- Get the "minute"
set Pos to offset of ":" in timeStr
set theMin to characters 1 thru (Pos - 1) of timeStr as string
set timeStr to characters (Pos + 1) through end of timeStr as string
--Get "AM or PM"
set Pos to offset of " " in timeStr
set theSfx to characters (Pos + 1) through end of timeStr as string
return (theHour & ":" & theMin & " " & theSfx) as string
end getTimeInHoursAndMinutes
set thetime to getTimeInHoursAndMinutes()
set ThePLISTNAME to random number from 0 to 1.0E+17
set A1 to display dialog "Enter in your title" default answer "" buttons {"Cancel", "Continue"} default button 2 with title "Notification Previewer"
set TITLE to text returned of A1
set A2 to display dialog "Enter in your text" default answer "" buttons {"Cancel", "Continue"} default button 2 with title "Notification Previewer"
set TEXT2 to text returned of A2
set A3 to display dialog "Enter in your subtitle" default answer "" buttons {"Cancel", "Continue"} default button 2 with title "Notification Previewer"
set TEXT3 to text returned of A3
set A4 to display dialog "choose a sound, LIST: Basso Blow Bottle Frog Funk Glass Hero Morse Ping Pop Purr Sosumi Submarine Tink. (CASE SENSITIVE)" default answer "" buttons {"Cancel", "Continue"} default button 2 with title "Notification Previewer"
set TEXT4 to text returned of A4
display notification TEXT2 with title TITLE subtitle TEXT3 sound name TEXT4
set textdata to {"Title: ", TITLE, "Text: ", TEXT2, "Subtitle: ", TEXT3, "Sound: ", TEXT4}
tell application "System Events"
set theParentDictionary to make new property list item with properties {kind:record, name:ThePLISTNAME}
--set fold to alias "~/Applications/Notification Previewer/Contents/Resources/Contents/Saves/"
--set TextFile to make new file at fold with properties {name:thetime, file type:"PLIST", creator type:"ttxt", type:«class fsrf»}
set thePropertyListFilePath to ("~/Applications/Notification Previewer/Contents/Resources/Contents/Saves/" & ThePLISTNAME & ".plist/")
set thePropertyListFile to make new property list file with properties {contents:theParentDictionary, name:thePropertyListFilePath}
tell property list items of thePropertyListFile
make new property list item at end with properties {kind:string, name:"stringKey", value:textdata}
end tell
end tell
What I'm trying to make is this:
set retry to true
repeat while retry is true
display dialog "In the next window you'll have to choose a color!" buttons {"Cancel", "COLORR!"} cancel button 1 default button 2
set Chosencolor1 to (choose color)
display dialog "The chosen color is: " & Chosencolor1 & " Is this right?" buttons {"NO", "YES"}
if the button returned of the result is "no" then
set retry to true
display dialog "Retry is now: " & retry
else
set retry to false
display dialog "Retry is now: " & retry
end if
end repeat
end
But when I run this code it will return a color code in numbers. But what I want is that it will return a color name like: light blue, blue, green etc.
The only way I know is to do something like:
if the chosencolor1 is "000" then
set the chosencolor1 to "Black"
end if
end
is there any other, more simple way to do this? Or is this just not possible?
Thanks for reading,
Jort
From the AppleScript Language Guide for choose color:
Result The selected color, represented as a list of three integers
from 0 to 65535 corresponding to the red, green, and blue components
of a color; for example, {0, 65535, 0} represents green.
As you have surmised, the only way to get a textual response is to program it yourself using the values of the list that your user chooses.
Here is a very simple example that adds all the values of the chosen RGB integers, and determines if it closer to black or white:
set myColor to choose color
display dialog ("You have chosen: " & my fetchColorName(myColor))
to fetchColorName(clst)
set totalColorValue to ((item 1 of clst) + (item 2 of clst) + (item 3 of clst))
set blackWhiteMidpoint to (196605 / 2)
if totalColorValue < blackWhiteMidpoint then
set colorName to "A color closer to black than white."
else
set colorName to "A color closer to white than black."
end if
return colorName
end fetchColorName
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
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