cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
JMP is taking Discovery online, April 16 and 18. Register today and join us for interactive sessions featuring popular presentation topics, networking, and discussions with the experts.
Choose Language Hide Translation Bar
mjoner
Level VI

JSL Identify Path of the Currently Running Script

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

Re: JSL Identify Path of the Currently Running Script

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

View solution in original post

10 REPLIES 10
pmroz
Super User

Re: JSL Identify Path of the Currently Running Script

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
Level VI

Re: JSL Identify Path of the Currently Running Script

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
Level VI

Re: JSL Identify Path of the Currently Running Script

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 (Alumni)

Re: JSL Identify Path of the Currently Running Script

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

Re: JSL Identify Path of the Currently Running Script

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
PhiIippe
Level II

Re: JSL Identify Path of the Currently Running Script

The solution is not working for me, the resulting path is with forward slashes /, I need it with backward slash \. Does someone know a solution?

Jeff_Perkinson
Community Manager Community Manager

Re: JSL Identify Path of the Currently Running Script

JMP and JSL don't care about the orientation of the slashes. They will work either way.

 

If you need to use the path string outside of JMP you can use Substitute Into():

 

foo="c:/my directory/my directory/my directory";

substitute into(foo, "/", "\");

show(foo);
-Jeff
PhiIippe
Level II

Re: JSL Identify Path of the Currently Running Script

Thanks Jeff, this is great!

I did find another solution though: I saved my script in the same directory as the current data table, then I get the path of my datatable:

 

dt = Current Data Table();
path = dt<< getpath;


The resulting "path" is my directory path with backward slashes

 

Re: JSL Identify Path of the Currently Running Script

There is also a built-in function to translate between the POSIX and Windows path delimiter:

 

convert.PNG