Group Abstract Group Abstract

Message Boards Message Boards

0
|
4.9K Views
|
8 Replies
|
4 Total Likes
View groups...
Share
Share this post:

How to set the unit system to the SI by default

I would like to share how to set the UnitSystem to the SI by default. To open the file, evaluate:

SystemOpen[FileNameJoin[{$UserBaseDirectory, "Kernel", "init.m"}]]

Then add this code:

$UnitSystem="Metric";

Then run the code and save the file. Then do the same for the file at

SystemOpen[FileNameJoin[{$BaseDirectory, "Kernel", "init.m"}]]

I have tried figuring out how to programmatically edit the init.m notebooks with like NotebookWrite or NotebookPut but I haven't figured it out so far. If anyone else knows how I could make this into a program that could be run in one iteration please comment.

POSTED BY: Peter Burbery
8 Replies
Posted 3 years ago

Hi Peter,

Here is one way to do it programmatically

stream = OpenAppend[FileNameJoin[{$UserBaseDirectory, "Kernel", "init.m"}]];
WriteLine[stream, "$UnitSystem=\"Metric\";"];
Close[stream];
POSTED BY: Rohit Namjoshi

Is there a way to specify that the Option Inspector should autosave every time a computation is evaluated and when I close a notebook as a global preference with the init.m file by writing a line like $AutosaveDefault=True or something? I would like to use to compile a program that will store the configuration I like to use for Mathematica so I can't easily transfer my preferences between computers.

POSTED BY: Peter Burbery

I modified the code to edit the $BaseDirectory as well:

userBaseDirectoryStream = 
  OpenAppend[FileNameJoin[{$UserBaseDirectory, "Kernel", "init.m"}]];
WriteLine[userBaseDirectoryStream, "$UnitSystem=\"Metric\";"];
Close[userBaseDirectoryStream];
BaseDirectoryStream = 
  OpenAppend[FileNameJoin[{$BaseDirectory, "Kernel", "init.m"}]];
WriteLine[BaseDirectoryStream, "$UnitSystem=\"Metric\";"];
Close[BaseDirectoryStream];
POSTED BY: Peter Burbery
POSTED BY: Peter Burbery
POSTED BY: Peter Burbery

I would like to mention that this only works if you have administrator privileges to access ProgramData. I tried running the program on a university computer as a student and I got a $Failed message.

POSTED BY: Peter Burbery
POSTED BY: Peter Burbery
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard