How to execute this code on startup?How to change the default Notebook stylesheetMake cursor stay in input cellHow to execute kernel command from Front End?Simple question about startup optionsIs there a way to hide or toggle the visibility of code?How would I improve this Karaoke machine code?Frontend cursor movement speed depends on the position in large notebook fileAutomatically execute command after saveHow to execute code on FrontEnd quit?How to execute a notebook in backgroundIs it possible to get rid of this information box?Evaluate Initialization cells at startup

Is using 'echo' to display attacker-controlled data on the terminal dangerous?

How long is it safe to leave marker on a Chessex battle map?

C++ logging library

How creative should the DM let an artificer be in terms of what they can build?

Can a human be transformed into a Mind Flayer?

Why did Intel abandon unified CPU cache?

Java Servlet & JSP simple login

Is it okay to have a sequel start immediately after the end of the first book?

How to write a convincing religious myth?

Separate SPI data

empApi with Lightning Web Components?

2019 gold coins to share

Has there been a multiethnic Star Trek character?

Is it possible to have 2 different but equal size real number sets that have the same mean and standard deviation?

The usage of kelvin in formulas

What is the color of artificial intelligence?

I have a problematic assistant manager, but I can't fire him

What is the logic behind charging tax _in the form of money_ for owning property when the property does not produce money?

Why did the World Bank set the global poverty line at $1.90?

Can I utilise a baking stone to make crepes?

Do you have to have figures when playing D&D?

Why am I getting a strange double quote (“) in Open Office instead of the ordinary one (")?

Who voices the small round football sized demon in Good Omens?

Can we completely replace inheritance using strategy pattern and dependency injection?



How to execute this code on startup?


How to change the default Notebook stylesheetMake cursor stay in input cellHow to execute kernel command from Front End?Simple question about startup optionsIs there a way to hide or toggle the visibility of code?How would I improve this Karaoke machine code?Frontend cursor movement speed depends on the position in large notebook fileAutomatically execute command after saveHow to execute code on FrontEnd quit?How to execute a notebook in backgroundIs it possible to get rid of this information box?Evaluate Initialization cells at startup













3












$begingroup$


Every time I open a new notebook I have to manually evaluate this code in that notebook. In order order to stop my cursor moving to a new cell.



How would I automate this?
I would love this functionality to auto-load on startup.



I have tried putting it in a file.m file and adding a Get["/path/to/file.m"] line, to my FileNameJoin[$UserBaseDirectory , "Kernel", "init.m"]. Unfortunately this does not work. As it seems to need to be evaluated in the SelectedNotebook[] to work.



Here is the code by @Kuba



With[
nb := EvaluationNotebook[]
, c := EvaluationCell[]

, With[
cv := CurrentValue[nb, "TaggingRules", "LastCursorPosition"]
, pos := FrontEndExecute@FrontEnd`UndocumentedGetSelectionPacket[nb]

, With[
savePosition := (
cv = If[MemberQ[pos, "CharacterRange" -> _], Last["CharacterRange" /. pos], False]
)

, SetOptions[nb
, CellEventActions :>
"MenuCommand", "HandleShiftReturn" :> savePosition
, "MenuCommand", "EvaluateCells" :> savePosition
, PassEventsDown -> True

, CellEpilog :> If[
IntegerQ[cv]
, SelectionMove[c, Before, CellContents]
; SelectionMove[nb, Next, Character, cv]
; cv = False
]
]
]
]
]









share|improve this question









$endgroup$
















    3












    $begingroup$


    Every time I open a new notebook I have to manually evaluate this code in that notebook. In order order to stop my cursor moving to a new cell.



    How would I automate this?
    I would love this functionality to auto-load on startup.



    I have tried putting it in a file.m file and adding a Get["/path/to/file.m"] line, to my FileNameJoin[$UserBaseDirectory , "Kernel", "init.m"]. Unfortunately this does not work. As it seems to need to be evaluated in the SelectedNotebook[] to work.



    Here is the code by @Kuba



    With[
    nb := EvaluationNotebook[]
    , c := EvaluationCell[]

    , With[
    cv := CurrentValue[nb, "TaggingRules", "LastCursorPosition"]
    , pos := FrontEndExecute@FrontEnd`UndocumentedGetSelectionPacket[nb]

    , With[
    savePosition := (
    cv = If[MemberQ[pos, "CharacterRange" -> _], Last["CharacterRange" /. pos], False]
    )

    , SetOptions[nb
    , CellEventActions :>
    "MenuCommand", "HandleShiftReturn" :> savePosition
    , "MenuCommand", "EvaluateCells" :> savePosition
    , PassEventsDown -> True

    , CellEpilog :> If[
    IntegerQ[cv]
    , SelectionMove[c, Before, CellContents]
    ; SelectionMove[nb, Next, Character, cv]
    ; cv = False
    ]
    ]
    ]
    ]
    ]









    share|improve this question









    $endgroup$














      3












      3








      3


      1



      $begingroup$


      Every time I open a new notebook I have to manually evaluate this code in that notebook. In order order to stop my cursor moving to a new cell.



      How would I automate this?
      I would love this functionality to auto-load on startup.



      I have tried putting it in a file.m file and adding a Get["/path/to/file.m"] line, to my FileNameJoin[$UserBaseDirectory , "Kernel", "init.m"]. Unfortunately this does not work. As it seems to need to be evaluated in the SelectedNotebook[] to work.



      Here is the code by @Kuba



      With[
      nb := EvaluationNotebook[]
      , c := EvaluationCell[]

      , With[
      cv := CurrentValue[nb, "TaggingRules", "LastCursorPosition"]
      , pos := FrontEndExecute@FrontEnd`UndocumentedGetSelectionPacket[nb]

      , With[
      savePosition := (
      cv = If[MemberQ[pos, "CharacterRange" -> _], Last["CharacterRange" /. pos], False]
      )

      , SetOptions[nb
      , CellEventActions :>
      "MenuCommand", "HandleShiftReturn" :> savePosition
      , "MenuCommand", "EvaluateCells" :> savePosition
      , PassEventsDown -> True

      , CellEpilog :> If[
      IntegerQ[cv]
      , SelectionMove[c, Before, CellContents]
      ; SelectionMove[nb, Next, Character, cv]
      ; cv = False
      ]
      ]
      ]
      ]
      ]









      share|improve this question









      $endgroup$




      Every time I open a new notebook I have to manually evaluate this code in that notebook. In order order to stop my cursor moving to a new cell.



      How would I automate this?
      I would love this functionality to auto-load on startup.



      I have tried putting it in a file.m file and adding a Get["/path/to/file.m"] line, to my FileNameJoin[$UserBaseDirectory , "Kernel", "init.m"]. Unfortunately this does not work. As it seems to need to be evaluated in the SelectedNotebook[] to work.



      Here is the code by @Kuba



      With[
      nb := EvaluationNotebook[]
      , c := EvaluationCell[]

      , With[
      cv := CurrentValue[nb, "TaggingRules", "LastCursorPosition"]
      , pos := FrontEndExecute@FrontEnd`UndocumentedGetSelectionPacket[nb]

      , With[
      savePosition := (
      cv = If[MemberQ[pos, "CharacterRange" -> _], Last["CharacterRange" /. pos], False]
      )

      , SetOptions[nb
      , CellEventActions :>
      "MenuCommand", "HandleShiftReturn" :> savePosition
      , "MenuCommand", "EvaluateCells" :> savePosition
      , PassEventsDown -> True

      , CellEpilog :> If[
      IntegerQ[cv]
      , SelectionMove[c, Before, CellContents]
      ; SelectionMove[nb, Next, Character, cv]
      ; cv = False
      ]
      ]
      ]
      ]
      ]






      front-end notebooks interface






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked May 25 at 12:50









      Conor CosnettConor Cosnett

      3,3871031




      3,3871031




















          1 Answer
          1






          active

          oldest

          votes


















          6












          $begingroup$

          Here's a stylesheet version that mimics Kuba's code:



          With[cv := CurrentValue[EvaluationCell[], TaggingRules, "LastCursorPosition"],
          SetOptions[EvaluationNotebook[],
          StyleDefinitions -> Notebook[

          Cell[StyleData[StyleDefinitions->"Default.nb"]],
          Cell[StyleData["Input"],
          CellEventActions ->
          "MenuCommand","HandleShiftReturn" :> Set[
          cv,
          Replace[
          Lookup[
          Developer`CellInformation @ EvaluationCell[],
          "CursorPosition"
          ],

          _, i_ -> i,
          _ -> False

          ]
          ],
          PassEventsDown->True
          ,
          CellEpilog :> Replace[cv,
          i_Integer :> (
          SelectionMove[EvaluationCell[], Before, CellContents];
          SelectionMove[EvaluationNotebook[], Next, Character, i];
          cv = False
          )
          ],
          TaggingRules ->
          ]
          ,
          StyleDefinitions->"PrivateStylesheetFormatting.nb"
          ]
          ]
          ]


          You can modify the default stylesheet to use for new notebooks, see the answers to How to change the default Notebook stylesheet.






          share|improve this answer











          $endgroup$












          • $begingroup$
            Thanks for your answer. I followed the link and I have successfully changed my default notebook stylesheet from Default.nb to DefaultModified.nb. I am confused. Where do I put your code? Do I paste it somewhere inside DefaultModified.nb?
            $endgroup$
            – Conor Cosnett
            May 26 at 14:11







          • 2




            $begingroup$
            @ConorCosnett If you have a stylesheet that you want to modify to include the above styles, you can open a new notebook and run the above code in the notebook. Then, edit the notebook stylesheet, copy the "Input" style, and paste it into the stylesheet you want to modify.
            $endgroup$
            – Carl Woll
            May 27 at 5:09











          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "387"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f199085%2fhow-to-execute-this-code-on-startup%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          6












          $begingroup$

          Here's a stylesheet version that mimics Kuba's code:



          With[cv := CurrentValue[EvaluationCell[], TaggingRules, "LastCursorPosition"],
          SetOptions[EvaluationNotebook[],
          StyleDefinitions -> Notebook[

          Cell[StyleData[StyleDefinitions->"Default.nb"]],
          Cell[StyleData["Input"],
          CellEventActions ->
          "MenuCommand","HandleShiftReturn" :> Set[
          cv,
          Replace[
          Lookup[
          Developer`CellInformation @ EvaluationCell[],
          "CursorPosition"
          ],

          _, i_ -> i,
          _ -> False

          ]
          ],
          PassEventsDown->True
          ,
          CellEpilog :> Replace[cv,
          i_Integer :> (
          SelectionMove[EvaluationCell[], Before, CellContents];
          SelectionMove[EvaluationNotebook[], Next, Character, i];
          cv = False
          )
          ],
          TaggingRules ->
          ]
          ,
          StyleDefinitions->"PrivateStylesheetFormatting.nb"
          ]
          ]
          ]


          You can modify the default stylesheet to use for new notebooks, see the answers to How to change the default Notebook stylesheet.






          share|improve this answer











          $endgroup$












          • $begingroup$
            Thanks for your answer. I followed the link and I have successfully changed my default notebook stylesheet from Default.nb to DefaultModified.nb. I am confused. Where do I put your code? Do I paste it somewhere inside DefaultModified.nb?
            $endgroup$
            – Conor Cosnett
            May 26 at 14:11







          • 2




            $begingroup$
            @ConorCosnett If you have a stylesheet that you want to modify to include the above styles, you can open a new notebook and run the above code in the notebook. Then, edit the notebook stylesheet, copy the "Input" style, and paste it into the stylesheet you want to modify.
            $endgroup$
            – Carl Woll
            May 27 at 5:09















          6












          $begingroup$

          Here's a stylesheet version that mimics Kuba's code:



          With[cv := CurrentValue[EvaluationCell[], TaggingRules, "LastCursorPosition"],
          SetOptions[EvaluationNotebook[],
          StyleDefinitions -> Notebook[

          Cell[StyleData[StyleDefinitions->"Default.nb"]],
          Cell[StyleData["Input"],
          CellEventActions ->
          "MenuCommand","HandleShiftReturn" :> Set[
          cv,
          Replace[
          Lookup[
          Developer`CellInformation @ EvaluationCell[],
          "CursorPosition"
          ],

          _, i_ -> i,
          _ -> False

          ]
          ],
          PassEventsDown->True
          ,
          CellEpilog :> Replace[cv,
          i_Integer :> (
          SelectionMove[EvaluationCell[], Before, CellContents];
          SelectionMove[EvaluationNotebook[], Next, Character, i];
          cv = False
          )
          ],
          TaggingRules ->
          ]
          ,
          StyleDefinitions->"PrivateStylesheetFormatting.nb"
          ]
          ]
          ]


          You can modify the default stylesheet to use for new notebooks, see the answers to How to change the default Notebook stylesheet.






          share|improve this answer











          $endgroup$












          • $begingroup$
            Thanks for your answer. I followed the link and I have successfully changed my default notebook stylesheet from Default.nb to DefaultModified.nb. I am confused. Where do I put your code? Do I paste it somewhere inside DefaultModified.nb?
            $endgroup$
            – Conor Cosnett
            May 26 at 14:11







          • 2




            $begingroup$
            @ConorCosnett If you have a stylesheet that you want to modify to include the above styles, you can open a new notebook and run the above code in the notebook. Then, edit the notebook stylesheet, copy the "Input" style, and paste it into the stylesheet you want to modify.
            $endgroup$
            – Carl Woll
            May 27 at 5:09













          6












          6








          6





          $begingroup$

          Here's a stylesheet version that mimics Kuba's code:



          With[cv := CurrentValue[EvaluationCell[], TaggingRules, "LastCursorPosition"],
          SetOptions[EvaluationNotebook[],
          StyleDefinitions -> Notebook[

          Cell[StyleData[StyleDefinitions->"Default.nb"]],
          Cell[StyleData["Input"],
          CellEventActions ->
          "MenuCommand","HandleShiftReturn" :> Set[
          cv,
          Replace[
          Lookup[
          Developer`CellInformation @ EvaluationCell[],
          "CursorPosition"
          ],

          _, i_ -> i,
          _ -> False

          ]
          ],
          PassEventsDown->True
          ,
          CellEpilog :> Replace[cv,
          i_Integer :> (
          SelectionMove[EvaluationCell[], Before, CellContents];
          SelectionMove[EvaluationNotebook[], Next, Character, i];
          cv = False
          )
          ],
          TaggingRules ->
          ]
          ,
          StyleDefinitions->"PrivateStylesheetFormatting.nb"
          ]
          ]
          ]


          You can modify the default stylesheet to use for new notebooks, see the answers to How to change the default Notebook stylesheet.






          share|improve this answer











          $endgroup$



          Here's a stylesheet version that mimics Kuba's code:



          With[cv := CurrentValue[EvaluationCell[], TaggingRules, "LastCursorPosition"],
          SetOptions[EvaluationNotebook[],
          StyleDefinitions -> Notebook[

          Cell[StyleData[StyleDefinitions->"Default.nb"]],
          Cell[StyleData["Input"],
          CellEventActions ->
          "MenuCommand","HandleShiftReturn" :> Set[
          cv,
          Replace[
          Lookup[
          Developer`CellInformation @ EvaluationCell[],
          "CursorPosition"
          ],

          _, i_ -> i,
          _ -> False

          ]
          ],
          PassEventsDown->True
          ,
          CellEpilog :> Replace[cv,
          i_Integer :> (
          SelectionMove[EvaluationCell[], Before, CellContents];
          SelectionMove[EvaluationNotebook[], Next, Character, i];
          cv = False
          )
          ],
          TaggingRules ->
          ]
          ,
          StyleDefinitions->"PrivateStylesheetFormatting.nb"
          ]
          ]
          ]


          You can modify the default stylesheet to use for new notebooks, see the answers to How to change the default Notebook stylesheet.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited May 25 at 14:00

























          answered May 25 at 13:55









          Carl WollCarl Woll

          83k3105216




          83k3105216











          • $begingroup$
            Thanks for your answer. I followed the link and I have successfully changed my default notebook stylesheet from Default.nb to DefaultModified.nb. I am confused. Where do I put your code? Do I paste it somewhere inside DefaultModified.nb?
            $endgroup$
            – Conor Cosnett
            May 26 at 14:11







          • 2




            $begingroup$
            @ConorCosnett If you have a stylesheet that you want to modify to include the above styles, you can open a new notebook and run the above code in the notebook. Then, edit the notebook stylesheet, copy the "Input" style, and paste it into the stylesheet you want to modify.
            $endgroup$
            – Carl Woll
            May 27 at 5:09
















          • $begingroup$
            Thanks for your answer. I followed the link and I have successfully changed my default notebook stylesheet from Default.nb to DefaultModified.nb. I am confused. Where do I put your code? Do I paste it somewhere inside DefaultModified.nb?
            $endgroup$
            – Conor Cosnett
            May 26 at 14:11







          • 2




            $begingroup$
            @ConorCosnett If you have a stylesheet that you want to modify to include the above styles, you can open a new notebook and run the above code in the notebook. Then, edit the notebook stylesheet, copy the "Input" style, and paste it into the stylesheet you want to modify.
            $endgroup$
            – Carl Woll
            May 27 at 5:09















          $begingroup$
          Thanks for your answer. I followed the link and I have successfully changed my default notebook stylesheet from Default.nb to DefaultModified.nb. I am confused. Where do I put your code? Do I paste it somewhere inside DefaultModified.nb?
          $endgroup$
          – Conor Cosnett
          May 26 at 14:11





          $begingroup$
          Thanks for your answer. I followed the link and I have successfully changed my default notebook stylesheet from Default.nb to DefaultModified.nb. I am confused. Where do I put your code? Do I paste it somewhere inside DefaultModified.nb?
          $endgroup$
          – Conor Cosnett
          May 26 at 14:11





          2




          2




          $begingroup$
          @ConorCosnett If you have a stylesheet that you want to modify to include the above styles, you can open a new notebook and run the above code in the notebook. Then, edit the notebook stylesheet, copy the "Input" style, and paste it into the stylesheet you want to modify.
          $endgroup$
          – Carl Woll
          May 27 at 5:09




          $begingroup$
          @ConorCosnett If you have a stylesheet that you want to modify to include the above styles, you can open a new notebook and run the above code in the notebook. Then, edit the notebook stylesheet, copy the "Input" style, and paste it into the stylesheet you want to modify.
          $endgroup$
          – Carl Woll
          May 27 at 5:09

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Mathematica Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          Use MathJax to format equations. MathJax reference.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f199085%2fhow-to-execute-this-code-on-startup%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Wikipedia:Vital articles Мазмуну Biography - Өмүр баян Philosophy and psychology - Философия жана психология Religion - Дин Social sciences - Коомдук илимдер Language and literature - Тил жана адабият Science - Илим Technology - Технология Arts and recreation - Искусство жана эс алуу History and geography - Тарых жана география Навигация менюсу

          Bruxelas-Capital Índice Historia | Composición | Situación lingüística | Clima | Cidades irmandadas | Notas | Véxase tamén | Menú de navegacióneO uso das linguas en Bruxelas e a situación do neerlandés"Rexión de Bruxelas Capital"o orixinalSitio da rexiónPáxina de Bruselas no sitio da Oficina de Promoción Turística de Valonia e BruxelasMapa Interactivo da Rexión de Bruxelas-CapitaleeWorldCat332144929079854441105155190212ID28008674080552-90000 0001 0666 3698n94104302ID540940339365017018237

          What should I write in an apology letter, since I have decided not to join a company after accepting an offer letterShould I keep looking after accepting a job offer?What should I do when I've been verbally told I would get an offer letter, but still haven't gotten one after 4 weeks?Do I accept an offer from a company that I am not likely to join?New job hasn't confirmed starting date and I want to give current employer as much notice as possibleHow should I address my manager in my resignation letter?HR delayed background verification, now jobless as resignedNo email communication after accepting a formal written offer. How should I phrase the call?What should I do if after receiving a verbal offer letter I am informed that my written job offer is put on hold due to some internal issues?Should I inform the current employer that I am about to resign within 1-2 weeks since I have signed the offer letter and waiting for visa?What company will do, if I send their offer letter to another company