having a slight problem

ok so i’m not sure if this is the right place for this but here goes…

so in my script i have two lists, one of numbers (ie. {“1”, “2”, “3”, “4”, “5”})

and one of signs (ie. {“+”, “-”, “*”, “/”})

my ultimate goal is that i can do something with these to DO MATH :smiley:

i want for the equation 1+2-3*4/5 to be solved with my script but i can’t figure out how to change the signs from text items to the actual operators. is there any way to do this or am i outa luck?

What you’re looking for is called an eval. Most interpreter languages have an eval but you have to be aware of the danger of using them. The eval command of applescript is run script.

run script "1 + 1" --result: 2 of class integer

What this does is interpreting the string as code and compile/execute it. When a string from a user input (from dialogs, input fields etc) is used inside an eval you have a security issue because users are able to run own code through injection.

ok thank you, but what would i actually put in the code to make this work for my situation?


i’ve tried code like
(the list of numbers is numberlist and the list of signs is signlist)

run script item 1 of numberlist item 1 of signlist item 2 of numberlist

this gives the error: Expected end of line, etc. but found class name.

so i tried just with the signlist

run script item 1 of signlist

which gave me the error: Scripting component error.

so i’m kinda lost D: