Defining constants

Hi all,
I am wondering on what is the best way for me to define constants values, using global, universal or are there better ways?

E.g. I have this bunch of images which are reusable in a lot of test scripts. As there are times I will either need to change the file names or location, I will have to go into all the scripts and update their location/file names or some common error messages. Hence, it will be best to be able to put them in some definiation form…eg. like we do #define in C++. Anyone?

Either global or universal variables would work in theory, but there are a couple of points to consider in practice:

If you use globals, you’ll need to run the script that defines the variables at the beginning of each run of scripts. If you run a set of scripts from the scheduler, each script will need to run the constant setup script if it is to have access to your constant definitions. And you won’t be able to do a run selection on a portion of the script that requires those constants to be defined.

If you use universal variables, you’ll only need to run the script that defines them once in each Eggplant session; scripts run from the scheduler will be able to access the constants once they have been defined without each script having to run the setup script; and you will be able to do run a selection that refers to those constants. The downside is that you wouldn’t be able to test whether a value was set (shouldn’t be doing that with a constant anyway) and you may get so used to having them defined that you forget to run the setup script when you need to (as when running from the command line).

One way of handling the defining of the scripts is to set up a file that defines a property list, like so:


If you make a mistake in formatting your data file, the value function will throw an error, but it won’t tell you specifically where the problem is. Then, assuming you saved this file as “~/Eggplant/constantDefs.txt”, you could have a setup script with the following line:

put the value of file "~/Eggplant/constantDefs.txt" into universal CONST

and you could reference your constants like this:

-- make sure to declare this universal variable
-- in each script that needs to access your constants
universal CONST 

SendMail( to: CONST.EmailAddress, subject:"hi", body:"I'm Eggplant.")
TypeText CONST.MetaKey
put file CONST.SuiteHome & "MySuite/Scripts/MyScript.script" into aScript

In this way you’ll have all of your constants defined in a central location, making them easy to update and add to.

Thanks for the interesting question. Please let us know if this isn’t clear or there is anything else that we can help you with.

Interesting…have I not come across such a need, it didn’t occur to me that Eggplant, with the simple yet powerful SenseTalk could do something like this. 8)

When you say “making a mistake in formatting the data file…”, what kind of mistakes are you refering to? Syntax? Thanks :smiley:

Yes, sorry, I meant syntax. Just watch out for typos.

Din have time till now to test out the concept. However, when I tried running the e.g provided, i get the following error when i execute the script:

Unable to take value of expression `’(reason:(null))
(SenseTalk Alert: SRUN_InvalidValueExpr)

I tried finding documentation relating to this and had tried several ways of formatting the txt file but not successful. The following is the content i have in the txt file and script:

put the value of file “\constantDefs.txt” into universal CONST

Please advice

I think it’s probably due to the backslash in your filename; it should be a forward slash. I tested the code before posting it to verify that it works.

ha ha…the slash was my typo. found out the real cause. the txt in Mac added a lot of CRAPS in the actual txt file :wink: Thanks a great deal