Skip to content

Instantly share code, notes, and snippets.

@phantomas1234
Created February 17, 2014 12:52
Show Gist options
  • Select an option

  • Save phantomas1234/9049989 to your computer and use it in GitHub Desktop.

Select an option

Save phantomas1234/9049989 to your computer and use it in GitHub Desktop.
Save notebook specific workspaces in Mathematica
saveWorkspace[path_String:"/Users/niko/tmp"]:=Module[{fileName},
fileName=StringJoin[Sequence@@Riffle[{"Workspace",ToString@Hash[Flatten[List@@("FileName"/.NotebookInformation[])[[1;;2]]],"MD5"],ToString[Round[AbsoluteTime[]]],".mx"},"_"]];
DumpSave[FileNameJoin[{path,fileName}],"Global`"];
];
loadWorkspace[path_String:"/Users/niko/tmp"]:=Module[{currentNotebookHash,paths},
currentNotebookHash=ToString@Hash[Flatten[List@@("FileName"/.NotebookInformation[])[[1;;2]]],"MD5"];
paths=SortBy[ToExpression[StringSplit[#,"_"][[-2]]]->#&/@FileNames["Workspace*"<>currentNotebookHash<>"*.mx",{path}],First];
Get[paths[[-1,2]]];
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment