Script Name

mandybrigwell

New member
Can the name of a script be accessed as a string within a script? I realise 'notify' allows you to specify the name of a script, but is this value accessible within the script, and is it set to a default value?

This is in no way an urgent request; I just have 61 scripts that I'd like to log their names, and it'd be a lot easier to copy and paste the same print command at the start of each script than go through one by one typing out their name.

Basically, does: print(scriptName); exist?
 

fronobulax

Developer
Interesting question.

Ignoring file extensions, I believe the script name is also the case sensitive filename.

If scriptMRULength is greater than zero, scriptMRULIst will contain an ordered list of script file names, delimited by ; with the most recently run/loaded first. Note that the list does not contain directory information so if your scripts directory has subdirectories this might be less than useful.

get_stack_trace() contains the file name but you'd need to write something to extract the script name.

What's your application?

dir *.ash (or ls *.ash) will give you a list of script :) If you are interested in which ones are actually used there are operating system level utilities that will log that a file has been accessed. if you are just doing some kind of extended debugging - you want the session log to indicate that your script was started, there may be other ways to accomplish that.
 

ckb

Active member
The filename of a script can be accessed with the variable __FILE__

Code:
print(__FILE__);

will print the filename of the script.

Documented in the Wiki here (about halfway down the page)

Also, this post.
 
Last edited:

mandybrigwell

New member
That's exactly what I was looking for: thank you!

fronobulax, I'm not using it for anything particularly important. Over time I've ended up with a folder of 61 different scripts which call each other from a main breakfast, automation and logout script. It's a huge unholy mess now, and I wish when I'd started that I'd got the scripts logging what they were doing a little better. I was hoping to put what turns out to be print(__FILE__); at the start of each one just so I can track when it's been run, and not have to go through each script typing in the names manually. It might help me tidy things up a little…
 
Top