5
$\begingroup$

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?

$\endgroup$
4
$\begingroup$
CurrentValue[$FrontEndSession, {InputAliases, "xx"}] = "X"

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

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

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:

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

        ]
 ]

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

| improve this answer | |
$\endgroup$
  • $\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 Dec 13 '14 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 Dec 13 '14 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 Dec 13 '14 at 22:18
  • $\begingroup$ @QuantumDot but this only sets aliases for one notebook. the question is broader, right? $\endgroup$ – Kuba Dec 13 '14 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 Dec 15 '14 at 4:08

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.