- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Get name of current script
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.
Jesper
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Get name of current script
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));
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Get name of current script
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();
);
);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Get name of current script
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.
Jesper
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Get name of current script
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";
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Get name of current script
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));
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Get name of current script
That was exactly what I deeded. Thank you
Jesper
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Get name of current script
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Get name of current script
Thanks @BioData41
As long as I use this in the script to reference it's own filePath it works when running the file by itself or when running the script from another script using Include().
scriptFilePath = Include File List()[1];