I have following question: can I easily determine location of init.m from within said init.m?

We need to use premade Mathematica script/program/addon (don't know proper term) which unfortunately expects to find all it's files in ToFileName[{$TopDirectory,"AddOns","Applications","program_name"}] (this is an excerpt from init.m) which is a location we do not have access to due to shared nature of computer it's going to be ran on.

I can easily change hard-coded location in init.m, but I would prefer if I could make init.m determine it's location and use it as a base for constructing full directory path.

I tried using NotebookDirectory[], but it points to location of notebook which calls init.m file, is there an easy way of determining location of init.m while executing said init.m?

  • $\begingroup$ @LeonidShifrin Yes, it does. In fact, I found that solution (FindFile[]) myself before asking this question, but it didn't work for me because I failed to notice the difference between ` and '. After copy-pasting from answer you linked and seeing it work I investigated further and found my error. Thanks. $\endgroup$
    – M i ech
    Commented Apr 3, 2020 at 14:29


Browse other questions tagged or ask your own question.