3

I'm using M13.1 on Windows 11. Every update I've received from Wolfram so far completely trashes all my customization to mMA (so I've quit updating now). I've managed to get back a lot if my settings by slowly changing them thru the options inspector. But I can't find where to put a system command to change the Path to certain directory.

Right now I have to put SetDirectory[{path to my data files}] in each notebook file I use.

I have found ...Roaming\Mathematica\Front End\init.m which contains a lot of stuff but I'm afraid to edit this file because one time in the past I did that and I had to completely reinstall mMA to get it working again.

Could someone please give me instructions to get this problem fixed? Thank you.

AsukaMinato
  • 9,758
  • 1
  • 14
  • 40
1.156
  • 31
  • 3

2 Answers2

1

There are several ways to achieve this. I am using the following directory:

$UserBaseDirectory

If you update mathematica, the ini file in this directory will not be touched. In this directory you will find the file:

Kernel\init.m

Now add to this file:

<< "full file name of your personal ini file"

Note, the name must include the whole path.

Now in you personal ini file you may include any command you like.

Daniel Huber
  • 51,463
  • 1
  • 23
  • 57
  • Mr Huber, thank you for responding. I looked and this $UserBaseDirectory points to the very init.m file I mentioned in my original post (the one I earlier edited and then mMA wouldn't even start up -- perhaps I put something not proper there). In any case, I do not want to put a init file there, just a path to where my data files are. Can I simply insert a line like "c:\backup" -- and put it anywhere in this init file? Thank you – 1.156 Nov 05 '23 at 13:18
  • I recommend to make a personal initialization file, save it in a convenient place and put all the personal stuff there. Then in the init. m only put the command"<< fullpathnameof your file". This will keep your personal stuff and the mathematica stuff nicely separated. – Daniel Huber Nov 05 '23 at 15:18
  • Sir, thank you for your patience so far but where I'm confused is what do I put in this "fullpathnameof your file". I think you are saying I should for example add "<<c:\backup\Robsfile.txt" to the existing Frontend\init.m. But what should I put in this Robsfile.txt file? My goal is simply to add a directory (eg, c:\backup) to the current $Path. I apologize for being so difficult but remember, the last time I put something into that init.m file, Mathematica wouldn't even start up. Regards, Rob – 1.156 Nov 06 '23 at 19:10
  • First, use foward shlashes "/" in mathemtica not "". E.g.: "<<c:/backup/Robsfile.txt" without the quotes. Then you can put all the command you like in Robsfile. E.g. SetDirectory{"someDirectory"}. – Daniel Huber Nov 06 '23 at 21:21
  • Mr. Huber, I very carefully added the line <<c:/backup/Robsfile.txt to the file init.m found in users....roaming\Mathematica\Frontend\ and in the Robsfile.txt I put the single line SetDirectory["c://backup//mMA"]. Then I did my usual Mathematica startup. The result was a window saying "serious startup error". Fortunately when I removed that single line in init.m, I was then able to start mMA with no problems. Of course I still have not found a way to modify the Path so I can use my data files. I do appreciate your time and efforts - Rob – 1.156 Nov 07 '23 at 17:33
  • I ran out of characters in above comment. Let me add that the most simple solution to my problem is to continue adding the SetDirectory["c://backup//mMA"] to all .NB files I create. Since I don't make that many, it's not a huge problem. Again, thank you for trying to help me. Rob – 1.156 Nov 07 '23 at 17:41
  • You should add quotes around the file name like: <<"c:/backup/Robsfile.txI". I just tried to set the directory on my machine and it works. – Daniel Huber Nov 07 '23 at 21:09
  • Here's the start of my init.m file; I added your suggestion (I think) <<"c:/backup/robsfile.txt" SetOptions[$FrontEnd, NotebookBrowseDirectory->"C:\Backup\DATA\M9\Elect & EM analysis", AutoOpenPalettes->{"SetFaceAndFont4.nb"}, ConversionOptions->{"ImportOptions"->{ "Package" -> {"BlankLinesBetweenCells" -> 2}}},..........my Mathematica will not start up with this added piece in the init.m ---have I put it in the wrong place in the file?? – 1.156 Nov 07 '23 at 23:42
  • Only <<"c:/backup/robsfile.txt" should go into the ini file. To test, put only e.g. Print["works"] into the robsfile.txt and check if you get this output. – Daniel Huber Nov 08 '23 at 08:01
  • Now only <<"c:/backup/robsfile.txt" is in the init.m file. In c:/backup/robsfile.txt is the single line Print["works"]. Now when I start M I get a blank window for a second or so and then it disappears. Mr. Huber I think your system is just different from mine. I think it will save us both a lot of time to just accept that. Thank you very much for your patience and I'm sorry I can't get things going here. Rob – 1.156 Nov 08 '23 at 18:36
  • Somewhere I found a comment or post that suggested "tutorial/GlobalAspectsOfWolframSystemSessions #122753064" (it appears I can't use a CR) I would like to look at this tutorial -- it may give me a clue how to solve my problem. Can someone tell me how to access this tutorial? Sorry I can't figure this out. Rob – 1.156 Nov 24 '23 at 21:39
0

In my Windows 10 system I found that

$UserBaseDirectory <> "/Kernel/init.m"

is the name of the file to add whatever personal commands you want.

You can check the current contents with

StringSplit[ReadString[$UserBaseDirectory <> "/Kernel/init.m"], "\n"]

to verify that it contains what you want there.

Somos
  • 4,897
  • 1
  • 9
  • 15