Importing the Contents of .txt Files Into Numbers


I'm creating a text file via terminal by running ls -tr > file.txt

It would be great to import/copy the contents of this text file into a specified column in Numbers.

The end goal is to have a spreadsheet that is updated from various .txt files into various columns representing the directories the .txt files came from.

Any ideas to get me started would be great! I can't seem to find a solution to get the data out of the .txt file into Numbers to start.

It depends on the context of the text file.

Numbers can open a plain text CSV (comma separated values) files.

Importing them in to specified columns may be more difficult.

But CSV files are relatively easy to work with (if your data is sufficiently simply that it doesn't require a bunch of quoting), so you could adjust the data to match the table columns which would make importing it much easier.

Hey William,

Welcome to the forum!  :sunglasses:

That sort of task gets "fun"...

It may be possible to do what you want with AppleScript.

There are some Numbers scripts on this forum, but I don't recall offhand what they do.

You can ask here:

It may also be possible to brute-force the Numbers UI with Keyboard Maestro.

Peter's idea may also be of use.


1 Like

Numbers will also treat tab as "next column" and return as "next row" when you paste. So you could generate your listings entirely within KM, using tabs and returns to separate your items, and simply paste everything in.

Also -- if you want a single-column list of the names of the files in a directory (and still want to use the command line to do it), use ls -1 -tr (you can use ls -1tr, but the extra space makes things clearer).

1 Like

I didn't even think to simply just open the .txt file in numbers! This gets me much closer. Thank you

1 Like

Thank you for sharing! I'll dig into this

1 Like

That sounds like a good path if the intention is to add this to an existing table.

Have Keyboard Maestro read the text file, process it so the columns match and are separated by tabs, and then save the result to the clipboard, then just Paste in to the table.