Processing a .csv file

I experienced something strange when processing a .csv file with AppleScript

edit and tldr; my mistake
The manual says the .csv file will be “imported and displayed as sheets”
I missed the point about converting to tab-delimited and possibly adding a header

These are transaction files from my bank in .csv format (text file, comma-delimited values)

DTP displayed the data as a spreadsheet so I opened the file with a text editor to confirm the .csv format
In AppleScript, working with the plain text version of the data

  • DTP had converted the data from comma-delimited to tab-delimited
  • For some files, DTP inserts a ABCD header row

Screen Shot 2021-04-01 at 20.40.21

What “Apple Script” did you use? Exactly how did you import the file into DEVONthink? What makes you think that the the file was changed from tab delimited to comma delimited? Do any or all of the files you mention actually have a header row (looks like the view just assumes first row is a header, which is reasonable). How is what you see different than what the DEVONthink Manual (page 46 of for version 3.6.3) says about CSV files?

I never looked at a CSV file in DEVONthink before. So I tried it with one of mine that was comma delimited and coincidently was from my bank. Yes, it displays the file as a table, using the first row as a header. After import, I also did a “open with” command to view the file that was inside DEVONthink with a text editor, and the delimiters were still commas. No changes to the source file.

I did a search/replace-all commas in the file to tabs, resaved as a new tab delimited file on Desktop, then imported into DEVONthink (drag and drop). Same results–viewed the file as a Table and there were no modifications to the delimiters.

So, if there were changes it must have been due to the Apple Script file you ran on the file? No?

Update Friday, 2 April 2021 at 06:57:00 BST: I edited the comma-delimited version of the file (using the open with a text editor) and removed the top header line. After saving the file, DEVONthink recognised that there was no header row and renamed the headers “A”, “B”, … Same result with doing the same experiment with the tab-delimited version. Can detect no changes made to the files by DEVONthink, as expected.

Import was via folder actions and the DTP - Import and Delete script
As I said, I confirmed the file is stored in DTP as comma-delimited (no changes to the source file)

So, if there were changes it must have been due to the Apple Script file you ran on the file? No?

My applescript code was

tell application id "DNtp" to set theBankcsvText to plain text of content record

At this point, I am working with tab-delimited data, with possibly an extra header row
edit; it’s important to note the script is working with the imported data, which may differ from the file data

I am unfamiliar with the instructions you made to tell DEVONthink to |set theBankcsvText to plain text of content record". What was your intent? If I would hazard a guess, I’m thinking that it was that instruction that changed the file. I also have no experience with the script to import and delete (but by it’s name it does not suggest it would modify the file).

What happens when you simply import the file (Menu: File/Import or drag and drop) and run no scripts on it?

My intent is to process the bank .csv file, and generate individual transaction notes. I use these for budget/expense reporting

What happens when you simply import the file (Menu: File/Import or drag and drop) and run no scripts on it?

The import does not change the file (still comma delimited), but the data is imported as tab-delimited with possibly a header added

So all well now?

Yep, I switched my code to tab-delimited, and ignored the ABCD header

edit: An even better solution is to not obtain the compromised text contents from DTP
Instead, I retrieved the file path from DTP and directly retrieved the file contents