Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

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

Posted on Oct 13, 2015 7:03 PM

Reply
Question marked as Best reply

Posted on Oct 13, 2015 7:08 PM

Here:


set choices to {M, D, A, S, E} (* make list *)

set the_button to (choose from list choices (* let me choose from the list *))

if the_button is false then return

if the_button contains M then

display dialog multiply


(134905)

2 replies

Oct 13, 2015 10:37 PM in response to chevydogincode

My guess is that you have some spill-over from a previous script that used 'display dialog' rather than 'choose from list'.


The problem lies in the part where you:


choose from listchoices(* let me choose from the list *)


if button returned of result is item 2 of choices then

The issue is that the chosen option is not part of the 'button returned' from 'choose from list'. 'button returned' is a property of the result from 'display dialog' where you can detect which button the user clicked. In the case of 'choose from list' the result is a list of the selected item(s) in the list, so you want to compare the actual result, not the 'button returned'. Neil's code shows you one way of doing this.

Applescript calculator gets error -1728

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.