Message Boards Message Boards

0
|
705 Views
|
2 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Creating a listing of the commands I typed while running Wolfram in a terminal window

Posted 1 month ago

I would like to have all the Mathematica commands entered during a terminal session, written exactly as typed to a text file. No Box wrappers, no HoldForm wrappers, just what I typed. Each on a separate line. And the commands should not be evaluated again when I "write" them to a file.

The idea is that I'm working, I type journalFile@"journal1.txt", and the file is open, written, and closed. I work some more and again type journalFile@"journal2.txt" and a newer, slightly larger file is created. So I would like a function journalFile.

Have experimented with $Echo, HoldForm, In and various combinations without luck. I can get close, with HoldForm wrapped around things, but don't want that.

POSTED BY: Paul Nielan
2 Replies

If I understand your request correctly this should do the trick

journalFile[file_] := With[
    {
        inputs = Replace[
            DownValues @ In,
            HoldPattern[RuleDelayed[_, input_]] :> ToString[Unevaluated[input], InputForm],
            {1}
        ]
    },
    Export[file, inputs, "Lines"]
]
POSTED BY: Jason Biggs
Posted 1 month ago

Thank you Jason. This worked for me. I tested it in both the command line via /Applications/Wolfram.app/Contents/MacOS/wolfram and in a notebook. It is a "pure" journal file in the way I asked for. Will be adding it to my bag of tricks.

It would be nice if the command-line app "logged" like this automatically. In days gone by, my most productive way of working with software in general was a cycle of (working interactively, generating a journal file, using a text editor to improve and format that file, then read it back into the interactive application) and repeat. GUI apps took that ability away for the most part. But the generality and power of a good text editor is still unsurpassed for many jobs.

I used it with CreateFile.

POSTED BY: Paul Nielan
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract