1
$\begingroup$

The code

CreateDocument[{},InputAutoReplacements->{"test"->DateString[]}];

generates a new notebook and "test" triggers an output containing the timestamp pertaining the evaluation moment of the CreateDocument function. I want, instead, get any time an updated timestamp, so I childishly tried

CreateDocument[{},InputAutoReplacements->{"test":>DateString[]}];

but unsuccessfully because an error is raised:

An unknown box name (DateString) was sent as the BoxForm for the expression. Check the format rules for the expression.

By the way, InputAliases exhibits the same behaviour.

Any hint would be very appreciated, thanks !

$\endgroup$
2
$\begingroup$

Not giving any guarantees but try with:

SetOptions[
  EvaluationNotebook[]
, InputAutoReplacements -> {
    "test" -> ToBoxes @ Dynamic[DateString[], DestroyAfterEvaluation -> True]
  }
]
$\endgroup$
2
  • $\begingroup$ If no quotes should be shown one might do SetOptions[EvaluationNotebook[], InputAutoReplacements -> {"test" -> ToBoxes[Style[Dynamic[DateString[], DestroyAfterEvaluation -> True], "Text", ShowStringCharacters -> False]]}] $\endgroup$ Jun 23 '20 at 6:20
  • $\begingroup$ @RolfMertig this adds StyleBox to the cell structure so I'd go with Dynamic[DateString[], DestroyAfterEvaluation -> True], depends what's OP need. $\endgroup$
    – Kuba
    Jun 23 '20 at 8:29

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.