Applescript calculator gets error -1728
My code worked formerly until I realized that my calculator will only do multiplication because of the conditions met from the list are always true. I need to be able to choose an operation but the I cannot get any sort of text or button (e.g. text returned of result or button returned of result) so I tried to just get around but clearly failed. I am at my wit's end. Thanks in advance for any help.
The error is:
error "Can’t get button returned of {\"multiplication\"}." number -1728 from button returned of {"multiplication"}
P.S. I already tried using "on error" to catch it before cancels the script but I couldn't get it to work.
display dialog "Enter value" with title "Calculator" with icon 2 default answer ""
set X to text returned of result
display dialog "Enter SECOND VALUE" with title "Calculator" with icon 2 default answer ""
set Y to text returned of result
try
set X to X as number
on error
display dialog "Cannot Calculate"
end try
try
set Y to Y as number
on error
display dialog "Cannot Calculate"
end try
set multiply to X * Y
set divide to X / Y
set add to X + Y
set subtract to X - Y
set exponent to X ^ Y
set M to "multiplication"
set D to "division"
set A to "addition"
set S to "subtraction"
set E to "exponential"
set choices to {M, D, A, S, E} (* make list *)
choose from listchoices(* let me choose from the list *)
if button returned of result is item 2 of choices then
display dialogmultiply
else if choices contains D then
display dialogdivide
else if choices contains A then
display dialogadd
else if choices contains S then
display dialogsubtract
else if choices contains E then
display dialogexponent
end if
MacBook Air