Saving Numbers Files in .CSV format

Hello, looking to this esteemed group for ideas. I use Numbers to maintain a number of .CSV files which are used as tables and configuration files for other applications. The problem I am having is every time I edit and save one of these files Numbers changes the file type. Is there anyway to get Numbers to preserve the .CSV file type when I save the file? The only way I’ve found to do this is to Export it as a CSV, delete the old file and then rename it back. Seems pretty clumsy. Alternatively any recommendations on other editors which will serve this purpose? I tried text edit but since many of the files are essentially two column tables Numbers makes creating and editing them much easier.

Thanks in advance,
Tim

Apple Numbers wants you to use the Numbers format, so they automatically convert the file for you.

The quickest way I know (and do) is use Finder to click on the CSV file. Numbers opens. Do my thing. Then Export to CSV, but instead of making a new CSV, save it on top of the old one and replace it. The file name will be grayed-out, but point to it anyway so you don’t have re-type the file name, and then do it.

1 Like

I have run into the same problem. My solution is to keep two versions of each data file. One is in Numbers format and the other is CSV. They are kept in the same folder with the same name except for the extension.

When I need to make a change, I open the Numbers file, do the editing, and then export the result to the CSV, overwriting the old version. To make the export go faster (no submenus or button clicking) and keep the two files in sync, I use this JXA script:

numbersApp = Application("Numbers");

// Get the top Numbers document and the path to its file (as a string).
let topDoc = numbersApp.documents[0];
let topPathString = topDoc.file().toString()

// Make the path to the CSV file we're going to export to.
// The only difference is the extension.
let csvPath = Path(topPathString.replace(/\.numbers$/, ".csv"));

// Save the Numbers file and export it as CSV to the path just created.
numbersApp.save(topDoc);
numbersApp.export(topDoc, {to: csvPath, as: "CSV"});

Because I have Keyboard Maestro, I use that to execute the script with ⌥⌘S. I’m sure there are other ways to run the script.

The disadvantage, of course, is that I have two copies of the same data. But I’ve decided wasting disk space is better than wasting my time dealing with Numbers’ automatic conversion.

2 Likes

Could you use Hazel to watch for changes to the Numbers file and automatically update the csv?

1 Like

That would be perfect if all the data files were in the same folder (which may be true for @qwikatb). In my situation, the data files for which I do this are in many, many folders. I think that means I’d have to set up a Hazel rule for each of those folders, which is more work than I want.

But I’m not very experienced with Hazel. Could I do it with a single rule?

1 Like

I’m not sure. If there’s a pattern to your folder names and hierarchies – eg, it’s always from a project folder to a sub folder of the same name (or same name but with the project name prepended or whatever), then I could imagine an approach that works, even if only with shell scripting.

Unfortunately I don’t know Hazel well enough (this my question, instead of a more useful suggestion…)

That said, if the folder structures are arbitrary and/or the destination folders don’t follow a regular naming and/or structural location, then it probably isn’t worth trying.

1 Like

I’m trying to understand how this would work, does Hazel have the ability to convert a numbers file to .CSV

This seems like the simplest way forward… Thanks

I re-looked at Hazel (which I’ve used for a long time) and it has no built-in way to convert Numbers file into CSV.

You could probably write an Applescript script to instruct Numbers to do it and then call that script in a Hazel rule that watches a folder … but I feel that would be way over the top. That being said I don’t really get how Hazel automation would be that useful in this situation, but maybe I’m not seeing the whole picture yet. All that up to you.

FYI, Microsoft Excel when opening a CSV file will save it back, as you are expecting. If it’s a big deal about Numbers doesn’t work for you, perhaps try Excel. If you are into automating things, Excel provides a very rich Visual Basic system which will probably help you more than Hazel and Numbers.

Me … I’d just Export back in CSV format to the original file, delete the Numbers file (as mentioned above). Automation doesn’t seem warranted here.

But if you are talking scores/hundreds/thousands of CSV files, maybe manual spreadsheet tools are not the answer, but that another matter probably.

Hmmm, when you save the Numbers file using numbersApp.save(topDoc); doesn’t Numbers ask you where to save it, Delete it, or Cancel? I used very similar code to what you have here and I get the Save As dialog, which I do not want. I don’t get why this comes up; it’s like pressing option-command-S.

Curious if you see the same.

When I use use that macro, the Numbers file already exists, so no, I don’t get asked where to save it.

Ah, of course. I am opening a .xlsx file and exporting as .csv. Unfortunately, Numbers then wants the user to save the original file as .numbers, which doesn’t exist in my case, so it asks where to save it. I don’t see a way around that save dialog.
Thanks.