BookmarkSubscribeRSS Feed
Choose Language Hide Translation Bar
Highlighted
johnmoore

Community Trekker

Joined:

Jun 19, 2014

Is there a way for a script to find the name of a script?

I have created a log usage function that records details of the script and some other information to a log file.  As it stands now, I need to pass the name of the script to the function so that it will log the usage.  For example:

log usage("Super fun script.jsl");

I would like be able to have the function find the name of the script that is calling it so that I could type:

log usage();

and the log usage would know that "Super fun script.jsl" called it and record that to the usage log.  This would save a lot of typing.

 

Many thanks,

 

John

 

1 ACCEPTED SOLUTION

Accepted Solutions
Craige_Hales

Staff

Joined:

Mar 21, 2013

Solution

Re: Is there a way for a script to find the name of a script?

a=savetextfile("$temp\deletemeA.jsl","show(includeFileList())");
b=open(a,"script");

b[ScriptBox(1)]<<run;

Include File List() = {"C:\Users\chales\AppData\Local\Temp\deletemeA.jsl"};

In the earlier example, the final item in the list was "" because it had not been saved. In this example, the final (and only) item in the list is the name of the file that is running the script.

Craige
6 REPLIES 6
ian_jmp

Staff

Joined:

Jun 23, 2011

Re: Is there a way for a script to find the name of a script?

Here's an indirect way that may or may not be general enough:

NamesDefaultToHere(1);

thisWin = CurrentWindow();
thisWinTitle = thisWin << getWindowTitle;
if(!EndsWith(thisWinTitle, ".jsl"), scriptTitle = thisWinTitle||".jsl", scriptTitle = thisWinTitle);
Print(scriptTitle);
johnmoore

Community Trekker

Joined:

Jun 19, 2014

Re: Is there a way for a script to find the name of a script?

Ian,

 

Thanks for your reply.  The script worked beautifully on its own, but did not give the result I was looking for when I included it as part of an add-in.

 

John

Craige_Hales

Staff

Joined:

Mar 21, 2013

Re: Is there a way for a script to find the name of a script?

Also, see IncludeFileList() in the scripting index. Here's a better example:

 

a=savetextfile("$temp\deletemeA.jsl","show(includeFileList())");
b=savetextfile("$temp\deletemeB.jsl","include(a)");
include(b);

Include File List() = {"C:\Users\chales\AppData\Local\Temp\deletemeA.jsl", "C:\Users\chales\AppData\Local\Temp\deletemeB.jsl", ""};

Craige
johnmoore

Community Trekker

Joined:

Jun 19, 2014

Re: Is there a way for a script to find the name of a script?

Craig,

 

Thanks for your reply.  Don't think I can use this for my particular application, but it great to know a new function.

 

John

Craige_Hales

Staff

Joined:

Mar 21, 2013

Solution

Re: Is there a way for a script to find the name of a script?

a=savetextfile("$temp\deletemeA.jsl","show(includeFileList())");
b=open(a,"script");

b[ScriptBox(1)]<<run;

Include File List() = {"C:\Users\chales\AppData\Local\Temp\deletemeA.jsl"};

In the earlier example, the final item in the list was "" because it had not been saved. In this example, the final (and only) item in the list is the name of the file that is running the script.

Craige
johnmoore

Community Trekker

Joined:

Jun 19, 2014

Re: Is there a way for a script to find the name of a script?

Craig,

 

Thanks for the clarification!  This will be great.  Many thanks for your help.

 

John