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

          RemoteApp sporadic failureWindows 2008 RemoteAPP client disconnects within a matter of minutesWhat is the minimum version of RDP supported by Server 2012 RDS?How to configure a Remoteapp server to increase stabilityMicrosoft RemoteApp Active SessionRDWeb TS connection broken for some users post RemoteApp certificate changeRemote Desktop Licensing, RemoteAPPRDS 2012 R2 some users are not able to logon after changed date and time on Connection BrokersWhat happens during Remote Desktop logon, and is there any logging?After installing RDS on WinServer 2016 I still can only connect with two users?RD Connection via RDGW to Session host is not connecting

          How to write a 12-bar blues melodyI-IV-V blues progressionHow to play the bridges in a standard blues progressionHow does Gdim7 fit in C# minor?question on a certain chord progressionMusicology of Melody12 bar blues, spread rhythm: alternative to 6th chord to avoid finger stretchChord progressions/ Root key/ MelodiesHow to put chords (POP-EDM) under a given lead vocal melody (starting from a good knowledge in music theory)Are there “rules” for improvising with the minor pentatonic scale over 12-bar shuffle?Confusion about blues scale and chords

          Esgonzo ibérico Índice Descrición Distribución Hábitat Ameazas Notas Véxase tamén "Acerca dos nomes dos anfibios e réptiles galegos""Chalcides bedriagai"Chalcides bedriagai en Carrascal, L. M. Salvador, A. (Eds). Enciclopedia virtual de los vertebrados españoles. Museo Nacional de Ciencias Naturales, Madrid. España.Fotos