4
$\begingroup$

I want to be able to access Notebooks on my laptop when travelling and don't have internet access. Currently, I save a copy to my laptop HHD disc, but this is annoying and I can get caught out by forgetting to save a notebook I need or forgetting to save the latest version.

Is there a better way?

$\endgroup$
  • 1
    $\begingroup$ Unfortunately I don't think the cloud syncs well with local files. You need to manually download and save files locally if you plan to go offline. $\endgroup$ – user6014 Mar 12 '18 at 0:28
3
$\begingroup$

If you NotebookOpen @ CloudObject[ url ] the opened notebook will be saved to the cloud automatically. So as long as you keep the FrontEnd up it will work.

If you can't keep it open/put to sleep etc you can try this idea:

cloudNotebook = CloudDeploy[
  Notebook[{Cell["test", "Section"]}],
  Permissions -> "Public"
];

createTempCloudNotebook @ cloudNotebook

createTempCloudNotebook fetches and opens a notebook from given link. You will need to pick a file destination when saving for the first time. But aside of that, each time you Ctrl+S it should check the connection and upload to cloud if possible. It will be manifested with a processing bar on top.

enter image description here

   createTempCloudNotebook // ClearAll;
createTempCloudNotebook[co_CloudObject] := 
 Module[{nb}, nb = NotebookPut@Import[co];
  SetOptions[nb, 
   DockedCells -> {Cell@
      BoxData@ToBoxes@
        DynamicModule[{saved = True, saveNotebook, cloudConnectedQ}, 
         DynamicWrapper[
          Row[{co, 
            Dynamic[
             If[Not@saved, 
              Dynamic@
               ProgressIndicator[Appearance -> "Indeterminate"], 
              ""]]}, Spacer[20]], If[Not@saved, saveNotebook[]];, 
          TrackedSymbols :> {saved}, SynchronousUpdating -> False], 
         SynchronousInitialization -> False, 
         Initialization :> (cloudConnectedQ[] := 
            Quiet[URLRead[
               HTTPRequest[
                "www.wolframcloud.com", <|"Method" -> "HEAD"|>], 
               "StatusCode"] === 200];

           saveNotebook[] := (If[cloudConnectedQ[], 
              SessionSubmit[CloudDeploy[#, co], 
                 HandlerFunctions -> <|
                   "TaskFinished" :> (saved = True)|>] &@
               EvaluationNotebook[], saved = True]);

           SetOptions[EvaluationNotebook[], 
            NotebookEventActions :> {{"MenuCommand", 
                "Save"} :> (saved = False), PassEventsDown -> True, 
              EvaluationOrder -> After}])]}]]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.