Thursday, January 19, 2017
  • Index
  •  » Core Language
  •  » Can I evaluate expressions in AppleScript, as in other languages?

#1 2005-10-31 04:54:16 am

julifos
Administrator
From: Malasa├▒a, Madrid
Registered: 2002-11-20
Posts: 2014

Can I evaluate expressions in AppleScript, as in other languages?

In short, no, but... The most similar thing would be using the command run script and passing text as direct parameter (and additional parameters, if needed). This command will attempt to compile and run the given text on-the-fly, and it will return any compilation or execution error (if any).

This is a very basic example:

Applescript:

set var to "1 + 2 + 3 + 4 + 5"

run script var --> 15

And a typical request from lots of users: get a variable's value thru it's name (as a string):

Applescript:

set var to {1, 2, 3, 4, 5}

evaluate("var") --> {1, 2, 3, 4, 5}

to evaluate(theThing)
   run script "on run {x}
├?┬ ├?┬ return x's "
& theThing & "
end"
with parameters {me}
end evaluate

Offline

 
  • Index
  •  » Core Language
  •  » Can I evaluate expressions in AppleScript, as in other languages?

Board footer

Powered by FluxBB

[ Generated in 0.038 seconds, 11 queries executed ]

RSS (new topics) RSS (active topics)