I am wondering how I could programmatically make Mathematica autosave by default.
There is an option in the Option Inspector (Ctrl+Shift+O) for Global Preferences to check the box for NotebookAutoSave and ClosingAutoSave.
I have a button that I have created to assign defaults I want to keep quickly, and I want to add a line that sets the settings above to be true as well.
How can I do this?
Button["Set unit system to SI and make vector maps by default and use \
full date strings by default",
userBaseDirectoryStream =
OpenAppend[FileNameJoin[{$UserBaseDirectory, "Kernel", "init.m"}]];
WriteLine[userBaseDirectoryStream,
"$UnitSystem=\"Metric\";GeoGraphics`$GeoBackgroundType = \
\"Vector\";$DateStringFormat=\"DateTime\";"];
Close[userBaseDirectoryStream];
BaseDirectoryStream =
OpenAppend[FileNameJoin[{$BaseDirectory, "Kernel", "init.m"}]];
WriteLine[BaseDirectoryStream,
"$UnitSystem=\"Metric\";GeoGraphics`$GeoBackgroundType = \
\"Vector\";$DateStringFormat=\"DateTime\";"];
Close[BaseDirectoryStream];]
Is there a reason for using a button to write these settings to init.m? Every time the button is clicked it appends new lines with the same settings. The button code should append only if the current value is different from the desired value.
at the end which I wouldn’t like.
I would need to process the settings to delete all cases of
$UnitSystem="Imperial";
so I have
$UnitSystem="Metric";
$UnitSystem="Metric";
and then I would need to delete the duplicates.
I would also need to add a check that if I have already written to the init.m file that it shouldn’t add another one. For example if the current file contains this
$UnitSystem="Metric";
It wouldn’t write one more time to have
$UnitSystem="Metric";
$UnitSystem="Metric";
I’m not sure how to do this though.
A program would have to be written for every setting including vector maps, autosave, SI units, and more. I think the solution would be a database.
I think the solution would be a database. There would be a business rule that you couldn’t add a value if it already had a value. For example, you could have an entity setting with the property value for the setting. I could add an entity unitsystem with the value “metric”. I could then implement a business rule and an integrity check constraint that you can’t add a new entity for a setting if the key already exists and you can’t update without permission to unprotect the data or something like that.