Skip to main content
TᴀW
Brainiac
May 11, 2017
Question

How to get full path of parent script that uses #include

  • May 11, 2017
  • 2 replies
  • 3190 views

Script A has an #include "ScriptB" line.

ScriptB now needs the full path of Script A -- i.e., exactly the info you get from $.fileName if you run that line in Script A.

But the command $.fileName if it appears in Script B returns the path to Script B, not Script A. (I always thought that #include actually causes the contents of the #include statement to be copied over to that location, but this proves that it is not quite so simple.)

Obviously, this path could be assigned to a variable in Script A and then used in Script B. But Script B is a library component, and the whole point is not to have to update the two-dozen Script A's that are calling Script B. So I would rather not have to modify all the Script A's. It would be better if Script B stays an independent module.

So: How to get the full path of Script A, when you're inside Script B, which has been #included in Script A?

For a moment I thought I had found an answer: The first line of the string $.stack is the file name of Script A. But it doesn't include the path, just the file name, so not good enough.

Can anyone help?

Thanks,

Ariel

This topic has been closed for replies.

2 replies

Loic.Aigon
Brainiac
May 12, 2017

Hi Marc,

From your experience, is there any reason to prefer $.setenv to scriptArgs ?

Loic

Marc Autret
Brainiac
May 12, 2017

Hi Loic,

scriptArgs is DOM-based (it requires app to be available) while $.setenv is a "low level" ExtendScript command.

@+

Marc

Loic.Aigon
Brainiac
May 12, 2017

I see thanks.

Loic.Aigon
Brainiac
May 11, 2017

Hi Ariel,

What about ScriptArgs ?

#include "scriptB.jsx"

app.scriptArgs.set("origin", $.fileName );

test();

And in scriptB :

function test()  {

  var origin = app.scriptArgs.isDefined ( "origin" )? app.scriptArgs.get ( "origin" ) : "unknown";

  alert( "Calling script location is :\r"+origin );

}

HTH

Loic

TᴀW
TᴀWAuthor
Brainiac
May 11, 2017

Hi Loic!

Not bad, but it still means modifying all the caller scripts, which I wanted to avoid.

Thanks,

Ariel

Loic.Aigon
Brainiac
May 12, 2017

Hi Ariel

from memory you have

app.activeScript which should return the path of the script being exécuted in indesign

but can't remember if that would be script à or b

loic