Subscribe Bookmark RSS Feed

Get name of current script

JesperJohansen

Community Trekker

Joined:

Apr 15, 2013

I am trying to find a way to add the name of a script to the report created by the script. This means that I need to get a text string of the script name at some point. I can that the script file directory:

sDir=Get Default Directory();

and the files within that directory:

lFiles=Files In Directory(sDir);

But I haven't found a way to get only the file name I get is of the script I am currently running. The problem is that when finding a saved report later, I want to know exactly which script was run to produce said report.

Please help.

BR
Jesper
1 ACCEPTED SOLUTION

Accepted Solutions
Solution

If the script is run from a script window, the direct approach in the example below give you the file name.

scr_name = Current Window() << get window title;

dt = Open("$SAMPLE_DATA/Big Class.jmp");

nw = New Window("My Report", Bivariate(Y(:weight), X(:height)), Text Box(scr_name));


6 REPLIES
vs90

Community Trekker

Joined:

Jun 16, 2015

Try using:

Contains(lFiles,"script.jsl");

I used this to locate a JMP table by using ".jmp" and it worked for me.

Or if I got your question wrong there is another way where you can loop over number of files in the directory and get the script file name like:

For(n=1,n<=N Items(lFiles),n++,

file=lfiles[n];

If(

Ends With(file,".jsl"),/*Do your thing*/;

Break();

);

);

JesperJohansen

Community Trekker

Joined:

Apr 15, 2013

I came up with almost the exact same script (the "For"-loop) before I posted my question. The problem with it is that I don't know if the script it returns is the current one. If for instance the same script is saved in different versions in the same folder I would get a list of .jsl-files. I need to get the name of the current script running no matter how many similarly named scripts may be saved in the same location.

BR
Jesper
pmroz

Super User

Joined:

Jun 23, 2011

Don't know if there's a way to do that.  I set a variable at the beginning of each script.  A bit tedious but helps with debugging.

pname = "My Script.JSL";

Solution

If the script is run from a script window, the direct approach in the example below give you the file name.

scr_name = Current Window() << get window title;

dt = Open("$SAMPLE_DATA/Big Class.jmp");

nw = New Window("My Report", Bivariate(Y(:weight), X(:height)), Text Box(scr_name));


JesperJohansen

Community Trekker

Joined:

Apr 15, 2013

That was exactly what I deeded. Thank you

BR
Jesper
BioData41

New Contributor

Joined:

May 10, 2017

Not sure how long this function has been around, as I am fairly new to JMP, and I just found this function myself while trying to solve a similar problem, but it seems that the function "Include File List()" returns a list of open files that are in the context of the executing script.  (By the way, the description of this function is only sort of informative, as is the case for most functions/methods/messages in the Scripting Index or online resources.)  

 

It seems that if this function is run at the top of the script before anything else is opened by the script that the script file path and script file name can be extracted from that as this is the only path returned at that point.  

When I tested it with other files open in JMP, and ran the script by double clicking it from Windows Explorer (with the script set to run on open without opening a script editor window by including "//!" at the top of the script), I get only the path of that script returned.  None of the other opened files are returned.