Message Boards Message Boards

0
|
2691 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

An easy way to do this is using an external editor and editing manually that file. On Macs it is in the directory /Users/yourusername/Library/Mathematica/Kernel/. You can find the directory in your system with Mathematica itself using:

FileNameJoin[{$UserBaseDirectory, "Kernel"}]

there you have your user init.m file. You can edit it with a text editor, no Word!, and write in the commands you want for ALL your Notebooks be pre-executed

I have just put

SetOptions[Plot, ImageSize -> Full]

as I want all my plots large and resizable by default

I also created a button to make all cloud deployments public:

Button["Set cloud deployment permissions to public by default", 
 userBaseDirectoryStream = 
  OpenAppend[FileNameJoin[{$UserBaseDirectory, "Kernel", "init.m"}]];
 WriteLine[userBaseDirectoryStream, "$Permissions=\"Public\";"];
 Close[userBaseDirectoryStream];
 BaseDirectoryStream = 
  OpenAppend[FileNameJoin[{$BaseDirectory, "Kernel", "init.m"}]];
 WriteLine[BaseDirectoryStream, "$Permissions=\"Public\";"];
 Close[BaseDirectoryStream];]

This could be useful to avoid having to set Permissions to public when repeatedly deploying things that you want to be public.

POSTED BY: Peter Burbery

I added another function to the button that creates vector maps by default:

Button["Set unit system to SI and make vector maps by default", 
 userBaseDirectoryStream = 
  OpenAppend[FileNameJoin[{$UserBaseDirectory, "Kernel", "init.m"}]];
 WriteLine[userBaseDirectoryStream, 
  "$UnitSystem=\"Metric\";GeoGraphics`$GeoBackgroundType = \
\"Vector\";"];
 Close[userBaseDirectoryStream];
 BaseDirectoryStream = 
  OpenAppend[FileNameJoin[{$BaseDirectory, "Kernel", "init.m"}]];
 WriteLine[BaseDirectoryStream, 
  "$UnitSystem=\"Metric\";GeoGraphics`$GeoBackgroundType = \
\"Vector\";"];
 Close[BaseDirectoryStream];]
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

I added a button that when you click on it the default is changed.

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

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
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract