This code

(SetOptions[#1, InputAliases -> {"xx" -> "X"}] & ) /@ Notebooks[];

will define the alias [esc]xx[esc] to be replaced with X in the front-end for all notebooks that are currently open.

However, I would also like the InputAlias to be applied to new notebooks that will be opened during the current session.

Is it possible to modify the code above to do this?


2 Answers 2

CurrentValue[$FrontEndSession, {InputAliases, "xx"}] = "X"

or, if you want the new settings to persist across sessions, use

CurrentValue[$FrontEnd, {InputAliases, "xx"}] = "X"
  • $\begingroup$ OP probably wants this to be preserved after session too. $\endgroup$
    – Kuba
    Commented Dec 13, 2014 at 17:53
  • $\begingroup$ @Kuba, updated just in case that's what the OP wants. $\endgroup$
    – kglr
    Commented Dec 13, 2014 at 18:41
  • $\begingroup$ I don't know, but now it is just a global setting so not the case either. $\endgroup$
    – Kuba
    Commented Dec 13, 2014 at 18:44

First of all, if you use:

SetOptions[EvaluationNotebook[], InputAliases -> {"xx" -> "X"}]

then you will replace all aliases with this one. But if you only want to add new one, there is a convenient way to add a suboption:

CurrentValue[EvaluationNotebook[], {InputAliases, "xx"}] = "X"

Now, all previous aliases are preserved.

Ok, to the point. I don't know of any event/option that can help you. But since you are using FrontEnd anyway, maybe tiny Palette in the corner is what you can accept:

         Print[DateList[], " updated aliases"];
              (CurrentValue[#, {InputAliases, "xx"}] = "X") &,
          Style["\[FreakedSmiley]", 18, Bold]


So each time you open/close a notebook it will reevaluate. Feel free to delete Print line.

  • $\begingroup$ Thanks for the explanation about SetOptions vs CurrentValue; that is most useful. The tiny palette is a very amusing, and I will use it for myself frequently. But I feel that it would be inappropriate to have that in a package that I will share with others :-D $\endgroup$
    – QuantumDot
    Commented Dec 13, 2014 at 21:44
  • $\begingroup$ @QuantumDot Yeah, but, if it works, it's not silly :P Could you say more about notebooks that are meant to be affected by this? All notebooks opened, or created, or somehow related to package? $\endgroup$
    – Kuba
    Commented Dec 13, 2014 at 21:56
  • $\begingroup$ Two examples: (1) if the user wants to open a new window (as a scratch pad, for example) and wants to do a few calculations using the package functions in the new window, it would be nice to be able to use the aliases there, too. (2) my package will also have documentation that is embedded with the Wolfram doc center. It would also be nice to have aliases working in the pages there, too. The answer CurrentValue[EvaluationNotebook[], {InputAliases, "xx"}] = "X" seems to do what I need. $\endgroup$
    – QuantumDot
    Commented Dec 13, 2014 at 22:18
  • $\begingroup$ @QuantumDot but this only sets aliases for one notebook. the question is broader, right? $\endgroup$
    – Kuba
    Commented Dec 13, 2014 at 22:37
  • $\begingroup$ oops.. you're right: I meant to say that kguler's answer CurrentValue[$FrontEndSession, {InputAliases, "xx"}] = "X" is what I really needed (it applies to future notebooks too). $\endgroup$
    – QuantumDot
    Commented Dec 15, 2014 at 4:08

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.