Message Boards Message Boards

0
|
1609 Views
|
2 Replies
|
1 Total Likes
View groups...
Share
Share this post:

How to use autosave by default programmatically?

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];]
POSTED BY: Peter Burbery
2 Replies

They are front-end options. To set them programmatically

CurrentValue[$FrontEnd, "NotebookAutoSave"] = True

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.

POSTED BY: Rohit Namjoshi

Yes, I have thought of that.
The problem would be that there could be something like

$UnitSystem="Metric";
$UnitSystem="Imperial";
$UnitSystem="Metric";

and then an edit could be made and it would add

$UnitSystem="Metric";
$UnitSystem="Imperial";
$UnitSystem="Metric";
$UnitSystem="Imperial";

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.

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