name of the calling script

I have a situation where a bunch of different scripts are calling one other script…

for example:

From ScriptA.script: send LogError to ReportError
From ScriptB.script: send LogError to ReportError


Is there a way to find out what the name of the script is that called ReportError? I want to know when ScriptA called ReportError. I’m hoping that there is a way to do this without passing the name of the script in as a parameter.


Thanks for the good question! I had to think about this one some, because there isn’t currently any function that will simply tell you what handler called the current handler. But it turns out there is a way to get what you want, and it’s very easy, although you’ll have to change the way you call your ReportError script. Instead of using the Send command, you’ll want to call the reporting script as a direct command, like this:


If (as it appears from your example) the ReportError script contains several handlers and you want to call the LogError handler in that script (presuming you have such a handler there, which overrides Eggplant’s own LogError command), you will want to first ‘start using’ the ReportError script (to insert it into the BackScripts, making all of its handlers available from any script) and then simply call LogError as a command, like this:

start using "ReportError" -- this is only needed once

-- (other code here)


In either case, your ReportError script (or its LogError handler) can then get the name of the script that called it by using ‘the target’ function:

Log "ReportError was called by " & the short name of the target

The trick here lies in the way SenseTalk messaging works. Every command sends a message – to the script object that is running (for a full description, please read the section on Messages in Chapter 9 of the SenseTalk Reference manual (pages 137-140 in the 1.5 version of the manual)).

The target function identifies the object to which the message currently being handled was sent (either a ReportError or LogError message, in the examples above). By calling it directly as a command (without using Send), the message is targetted to the script that is doing the calling, which is the one you want to identify.

If you use Send to send the message to the ReportError script, the target will always be the ReportError script object, so it won’t give you any useful information. This is why you need to use ‘start using’ or make sure the ReportError script is available in the current suite or one of its Helper suites for this technique to work.

I hope this is all clear and helpful!

That does it thanks!