Apparently I'm having a problem even asking my question correctly and getting my edits to appear, so I'm asking the question once again. Hopefully it will go through and I'll get a specific answer.

HyperCard was a great Apple program which I used to take notes on what I read. I accumulated 100+ megaBytes of (mostly) text. The last Apple computer which could run it uses the PowerPC G5. Newer Apples won't run HyperCard as their memory management is different. Nothing lasts forever, and I'm down to my last Apple PowerPC G5 hence the reason for the move.

The HyperCard data is in the form of several types of cards (xref, glossary, index, topics). I wrote programs in HyperCard to move their data and data about them (e.g.metadata) into text files, which are basically a list of strings. These are loaded into the variable iData[] in a Mathematica program which allows me to access each string.

Here is the data and metadata on just two index cards, loaded into a Mathematica noteBook.

In[77]:= iData = 
  Import [ 
  "/Users/lewisrobinson/Desktop/Hypercard Xref/  IndexCards  100  to  \
 101", "lines" ] 

Out[77]= {"Total Number of Cards =  2 ", "Begin  card \"I2582705\" ",     \
 "card id 2582705 ", "5 hydroxylysine ", "No Topic Assigned ", "No \
  Topic Identifier ", "3 ", "\"Structure \" ", "1850661    \"glossary\" \
  ", "\"Deficiency in type VI Ehlers Danlos syndrome\" ", "1048186    \
  \"Xref\" ", "\"Lysyl hydroxylase\" ", "2927558    \"Xref\" ", "End  \
  card \"I2582705\" ", "Begin  card \"I5074462\" ", "card id 5074462 ",    \
 "5 methoxy Tryptophan (5MTP) ", "Serotonin ", "t239 ", "1 ", "\"An \
 endogenous anti-inflammatory agent\" ", "2105283    \"Xref\" ", "End  \
  card \"I5074462\" "}

Here is the sort of manipulation I do on iData[]

 In[78]:= iData[[1]] 

 Out[78]= "Total Number of Cards =  2 "

In[90]:= (* Now mimic CardManipulation10.nb *) numCardsS = StringExtract [ data[[1]], 6]

 Out[90]= "2"

 numIndexCardsI = ToExpression [numIndexCardsS]

 Out[91]= 2

There is a lot of error checking at each step -- example

 If [ IntegerQ  [ numIndexCardsI], Null, showIndexCardVariables [] ]

iDataLN is an integer pointing to a particular string in iData[] Here is one such example of its use

  In[106]:= iCardTitle = iData [[iDataLN]]

  Out[106]= "5 hydroxylysine "

There is a lot more of this sort of thing as I march through iData[], with many strings given names like iCardTitle etc. etc.

But here is the nub of my question

I went to the File menu of Mathematica and chose new notebook and then saved it as Index.nb and then opened it.

What I want to do is write the string "5 hydroxylysine " to Index.nb

How do I do this? I'm embarrassed to be asking such a simple question, but until I can write strings like this into notebooks of my choice my programming has ground to a halt. I realize that this is similar to a question I've asked previously, but the devil appears to be in the details about how files are named and where they are, and Index.nb is a new file in the Mathematica environment.

  • $\begingroup$ It sounds to me like you want to write to text files, not notebooks. $\endgroup$
    – lericr
    Commented Oct 30, 2022 at 15:37
  • 1
    $\begingroup$ Regarding your preamble, yes you’re having difficulty. This is very difficult to understand. $\endgroup$
    – lericr
    Commented Oct 30, 2022 at 15:39
  • 1
    $\begingroup$ If you’ve opened index.nb and you want to write something to it, that’s what the keyboard is for. $\endgroup$
    – lericr
    Commented Oct 30, 2022 at 15:40
  • 1
    $\begingroup$ You have a text file with data. You have a new notebook. You read and process the data on the notebook. You save the notebook as index.nb. You open the notebook. And….. what? More processing of text file? Manually adding a string to the text file? Reading a different text file? Writing to a file? $\endgroup$
    – lericr
    Commented Oct 30, 2022 at 15:48
  • $\begingroup$ Since ultimately this seems to stem from an attempt to port your HyperCard stacks, have you considered LiveCode or SuperCard? $\endgroup$
    – MarcoB
    Commented Oct 30, 2022 at 16:10

1 Answer 1


Edit: An easy way

  Cell["5 hydroxylysine", "Text"]]


This may not be the best way, but it seems to work for me.

nbList = Notebooks[];

target = First@Select[nbList,
    MemberQ[NotebookInformation[#], "Index.nb", ∞] &];

    Cell[BoxData[RowBox[{"5 hydroxylysine"}]], "Text"]

The first line of code makes a list of all open notebooks. When I click on Window in the toolbar, I see 3 notebooks listed. One of them is Index.nb, but it is not selected. The first line of code returns a list of NotebookObjects.

The second line of code detects which NotebookObject in the list has the filename "Index.nb". If the target notebook is open, the variable target will be it, as a NotebookObject.

The third line writes the string to a new cell in the target notebook. The new cell has the style "Text". Other cell styles are listed when I click on the Format->Style in the main toolbar. The new text cell goes in wherever the cursor in the target notebook happens to be. I recommend reading every word of the documentation on NotebookWrite and NotebookApply.

For more examples, I would search this forum for NotebookWrite or BoxData. For more information I would (also maybe try to) read the low level notebook programming guide.


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.