Reading past efforts to "Macrofy" Mathematica, it appears that the choice is between "FrontEndExecute" and a ResourceFunction "AddMenuItem" both of which are daunting. I do not want to modify the front end and foul up all my other Mathematica activities. Presently I am regularly pasting a graphic into a notebook which I then want to center and make the cell unevaluatable. Doing that requires typing


It would be nice to program a hotkey for that.

@Kuba sent me in the right direction but the code example there

<|"Label" -> "Center", "ShortKey" -> "c", "Action" :>FrontEndExecute[{SelectionMove[InputNotebook[], All, CellContents], 

represents just the danger I wish to avoid (my comment about "daunting" is like the other comment in this thread about FrontEndExecute entailing too much "burden"). While I know better than to evaluate something that deletes my entire notebook, what I do not know is what to substitute in its place. A snippet of code for my particular needs is what I am missing. Sorry to be such a wimp...

  • $\begingroup$ Is this an acceptable solution: mathematica.stackexchange.com/a/212851/5478? $\endgroup$
    – Kuba
    Commented Apr 5, 2023 at 16:13
  • $\begingroup$ I didn't mean to use the action from the linked answer but the NotebookActions feature where you can put your code. And if you need the code as well, is the final cell supposed to be an Output cell, or input or what? $\endgroup$
    – Kuba
    Commented Apr 5, 2023 at 19:51

1 Answer 1


Does it fit your needs?

 FrontEndExecute[FrontEndToken[InputNotebook[], "Paste"]];
 SelectionMove[InputNotebook[], All, Cell];
 cell = First@SelectedCells@InputNotebook[];
 SetOptions[cell, TextAlignment -> Center, Evaluatable -> False]

You can test it with

CreatePalette @ Button["TEST", (*code here *)]

and if it does you can use it in NotebookActions like in 212851:

  "Label"    -> "Paste and center", 
  "ShortKey" -> "c", 
  "Action"   :> (*code here *)

If NotebookActions does not work the way you like it then consider using a Palette like in a test above. Here are more alternatives too: 217028


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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