3
$\begingroup$

I tried modifying the Window menu section of MenuSetup.tr file inside $UserBaseDirectory/SystemFiles/FrontEnd/TextResources/Macintosh as follows

Menu["Window", 
    {
        MenuItem["Minimize", "WindowMiniaturize", MenuKey["m", Modifiers->{"Command"}]],
        MenuItem["Zoom", "ZoomWindow", MenuKey["/", Modifiers->{"Command", "Option"}]],
        Delimiter,
        Menu["Magnification", 
        {  (* added code start *)
            MenuItem["Larger", KernelExecute[AddTo[CurrentValue[SelectedNotebook[], Magnification] ,.2]], MenuKey["=", Modifiers->{"Command", "Shift"}], Scope->NotebookDefault],
            MenuItem["Smaller", KernelExecute[SubtractFrom[CurrentValue[SelectedNotebook[], Magnification],.2]], MenuKey["-", Modifiers->{"Command", "Shift"}], Scope->NotebookDefault],
            Delimiter,
            (* added code end *)
            LinkedItems[{
                MenuItem["50%", Magnification->0.50, Scope->NotebookDefault],
                MenuItem["75%", Magnification->0.75, Scope->NotebookDefault],
                MenuItem["100%", Magnification->1.00, Scope->NotebookDefault],
                MenuItem["125%", Magnification->1.25, Scope->NotebookDefault],
                MenuItem["150%", Magnification->1.50, Scope->NotebookDefault],
                MenuItem["200%", Magnification->2.00, Scope->NotebookDefault],
                MenuItem["300%", Magnification->3.00, Scope->NotebookDefault]
            }]
        }],

However, this does not work and I get the following error when trying to invoke "Larger" from the menu:

message

Note that the KernelExecute[some args] command that I have added works perfectly fine in a standalone notebook frontend and tries to mimic other KernelExecute commands found in MenuSetup.tr.

Can someone point me in the right direction?

P.S.: Replacing the AddTo[] and SubtractFrom[] commands by their explicit versions x=x+.2 or x=x-.2, does help get rid of the error message, but doesn't change the magnification itself.

$\endgroup$
5
  • $\begingroup$ AddTo and SubtractFrom can only be applied to symbols not to values. $\endgroup$ Commented Jan 2, 2022 at 8:40
  • $\begingroup$ They still do work in the frontend. Also, there are some commands like KernelExecute[CompoundExpression[CurrentValue[SelectedCells[InputNotebook[]], CellFrame] = Inherited, CurrentValue[SelectedCells[InputNotebook[]], CellFrameColor] = Inherited]] already in MenuSetup.tr which I tried mimicking. $\endgroup$
    – qreus
    Commented Jan 2, 2022 at 9:41
  • $\begingroup$ FrontEndExecute[AddTo[1, 1]] gives an error? $\endgroup$ Commented Jan 2, 2022 at 9:45
  • $\begingroup$ I think I probably need to use some undocumented low-level commands, hard to guess since KernelExecute[] is not documented $\endgroup$
    – qreus
    Commented Jan 2, 2022 at 10:02
  • $\begingroup$ @DanielHuber yes it does, but CurrentValue[] allows assignments of the form CurrentValue[item]=val $\endgroup$
    – qreus
    Commented Jan 2, 2022 at 10:05

1 Answer 1

3
$\begingroup$

After a bit more tinkering and careful mimicking of the existing code inside MenuSetup.tr, I finally landed on a working solution.

I have set

command + shift += = zoom in

command + shift +- = zoom out

increment/decrement amount = 0.2 (or 20%)

MenuItem["Larger", KernelExecute[Block[{oldmag = CurrentValue[SelectedNotebook[], Magnification]}, 
                        CurrentValue[SelectedNotebook[], Magnification] = oldmag + .2]], MenuKey["=", Modifiers->{"Command", "Shift"}], MenuEvaluator->"System", Scope->NotebookDefault],
MenuItem["Smaller", KernelExecute[Block[{oldmag = CurrentValue[SelectedNotebook[], Magnification]}, 
                        CurrentValue[SelectedNotebook[], Magnification] = oldmag - .2]], MenuKey["-", Modifiers->{"Command", "Shift"}], MenuEvaluator->"System", Scope->NotebookDefault],

The key bindings used above may need to be changed depending on one's existing key bindings.

Note: Both Block and MenuEvaluator->"System" are crucial in the above code, otherwise Mathematica will panic. You can however drop the Scope->NotebookDefault option as SelectedNotebook[] kind of already defines the scope.

$\endgroup$

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.