2
$\begingroup$

In Mac's mail app the key shortcut "command + option + c" gives a copy selected text style and "cmd + opt + v" pastes the style. Is there a way to achieve this with cell styles? The keyboard part is solved in this post, I'm just not sure how to effect the "copy-style" part of this problem.

$\endgroup$
  • $\begingroup$ What exactly do you mean by cell styles? Are you referring to the Stylesheet types accessed in the Format > Style menu, or to formatting applied at the Cell level (font size, background color, etc.)? $\endgroup$ – Mr.Wizard Feb 18 '15 at 18:01
  • $\begingroup$ Both or either would be nice. $\endgroup$ – M.R. Feb 18 '15 at 20:11
4
$\begingroup$

I achieved my goal with this code in MenuSetup.tr. Here is copy-cell-style:

MenuItem["Copy Cell Style",
        FrontEndExecute[{FrontEnd`SelectionMove[FrontEnd`EvaluationNotebook[], All,         FrontEnd`EvaluationCell],
            KernelExecute[
                $mystyle = FrontEndExecute[FrontEnd`NotebookRead[FrontEnd`EvaluationNotebook[]]];
					$mystyle = $mystyle[[2]];
            ]
        }],
      MenuKey["c", Modifiers -> {"Command", "Shift"}], MenuEvaluator -> "Local"]

and paste-cell-style:

MenuItem["Paste Cell Style",
            FrontEndExecute[{FrontEnd`SelectionMove[FrontEnd`EvaluationNotebook[], All, FrontEnd`EvaluationCell],
 KernelExecute[
 $mycell = FrontEndExecute[FrontEnd`NotebookRead[FrontEnd`EvaluationNotebook[]]];
    $mycell = $mycell[[1]];FrontEndExecute[FrontEnd`NotebookWrite[FrontEnd`EvaluationNotebook[],Cell[$mycell,$mystyle]]];
                ]
            }],
          MenuKey["v", Modifiers -> {"Command", "Shift"}], MenuEvaluator -> "Local"]
$\endgroup$
  • 1
    $\begingroup$ @Mr.Wizard In conclusion, we can only use System calls like Set[] friends inside KernelExecute, and we can only use Frontend calls inside FrontEndExecute, and these might have to be wrapped inside each-other depending on context... $\endgroup$ – M.R. Feb 23 '15 at 16:36
  • $\begingroup$ Does no-one find this useful? $\endgroup$ – M.R. Feb 26 '15 at 22:56
  • $\begingroup$ @anyone hmmmmm? $\endgroup$ – M.R. Mar 3 '15 at 1:42
  • $\begingroup$ For what it's worth I find it useful and you have my vote on both question and answer. $\endgroup$ – Mr.Wizard May 15 '15 at 7:39

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.