BookmarkSubscribeSubscribe to RSS Feed

JSL Identify Path of the Currently Running Script

Highlighted
mjoner

Community Trekker

Joined:

Jun 23, 2011

When running a script (either from the script window or by triggering it from the add-in) I would like to be able to either (1) get at the location of the directory that the script window is in or (2) get the id of the add-in that contains the script. JMP knows this because it had to open the script to start executing this. Is there a way to do this?

I know I can do this in an add-in context by using $ADDIN_HOME(id). The issue here is I have a common include that I am packaging in multiple add-ins, and I'd rather not have to change the file for each different add-in. I can see myself accidentally making a copy of the common include from add-in #1 to add-in #2 and forgetting to change the id in the include so that it uses the right path in add-in #2.

1 ACCEPTED SOLUTION

Accepted Solutions
Justin_Chilton

Joined:

Aug 27, 2015

Solution

I typically use either the Get Default Directory function or the Convert File Path function with an empty string to get the path of the current script.

path1 = Get Default Directory();
path2 = Convert File Path( "" );

Show( path1, path2 );

Here's the log when I run this script from a file located within my "C:\Public" folder:

path1 = "/C:/Public/";
path2 = "/C:/Public/";
Justin
5 REPLIES
pmroz

Super User

Joined:

Jun 23, 2011

Why not make the common include file it's own addin.  That way you can include it via something like:

// Load functions common to various apps
include("$ADDIN_HOME(com.cmpny.dept.common)\General Functions.jsl");
mjoner

Community Trekker

Joined:

Jun 23, 2011

Yes, but I want to include a line in General Functions.jsl that identifies which other add-in is calling a function in General Functions.jsl.

In other words, in com.cmpny.dept.addin1 a script might call a function in General Functions.jsl. I want to refer to a variable in General Functions.jsl that will reveal that com.cmpny.dept.addin1 called it.

mjoner

Community Trekker

Joined:

Jun 23, 2011

If I can't get that com.cmpny.dept.addin1 called it, and I DON'T use the common add-in approach pmroz is suggesting, then knowing what folder that script was in is good enough because I can open the addin.def from the same folder and extract the id from there.

 

This actually gives me a second potential application. If I can get in the addin.def of a currently-running add-in (but right now I can't seem to do this), I could do a version check by getting the id and addinVersion from addin.def and then compare that to a list of latest add-in versions that I might get using Internet Open. I could then find out whether the user's local addinVersion is the latest and greatest.

David_Burnham

Super User

Joined:

Jul 13, 2011

Get Default Directory combined with locating the DEF file sounds like it would work but seems like an uncomfortable hack.  The payback is probably worth it - I have a standard include file for all my filepath definitions but with separate revisions for each addin (i.e. the same problem you describe) so being able to dynamically discover the ID of the parent addin would be an extremely useful feature.  So much so, the hack is starting to sound attractive - hadn't thought about reading the DEF file ...

-Dave
Justin_Chilton

Joined:

Aug 27, 2015

Solution

I typically use either the Get Default Directory function or the Convert File Path function with an empty string to get the path of the current script.

path1 = Get Default Directory();
path2 = Convert File Path( "" );

Show( path1, path2 );

Here's the log when I run this script from a file located within my "C:\Public" folder:

path1 = "/C:/Public/";
path2 = "/C:/Public/";
Justin