Problem Importing Plain Text

I recently found Scrivener and am really impressed! One problem I have found is related to importing plain text files. I primarily do technical writing and often include Java and XML examples in my writing. I was hoping I could add these *.java and *.xml files in the Research section, but I get an error attempting to drag and drop these into Scrivener as it believes they are unsupported file types. The content type of these files is always ASCII or UTF-8, so according to the FAQ, they should be importable types. I’m assuming Scrivener is looking at the file extension rather than the content type because if I give the file a .txt extension they import fine.

Please let me know if I am missing something.


I think you are right, it is looking at the extension and thinking it is something it cannot deal with. It probably works on the principle of accepting what it knows, and assuming everything else it cannot understand – so it does not realise that these files are just as much text as a .txt file. Something you could consider doing is using a batch rename program to convert everything from file.xml to file-xml.txt, and file-java.txt. Once it is in Scrivener, it doesn’t really matter any more, what the extension is, it just becomes another snippet of text like everything else. Putting the old extension in the new name will help you quickly identify what is what, in a list.

bobmccune has pointed out an important problem. Is it too late in the development cycle to address it? Wouldn’t it be pretty straightforward to put up a dialogue asking the user whether she wants to import an unrecognized file as plain text?. Perhaps there should be a preference item allowing additions and deletions of extensions to a list of recognized plain text types.


If change is indeed possible, I like your last idea best. Opening it up to importing everything unknown as text would reduce the usefulness of bulk import operations. Currently, you can trust S to weed out binaries and such. Having a “accept” list to treat as text would retain that capability, while opening up the scope based on user usage.

There is unfortunately no way in Cocoa to tell whether a file is plain text or not by anything other than its extension. Plain text is actually rather prickly when it comes to importing. Amber gives good advice - just get rid of the extensions for the sake of importing, or change them to .txt and they will import fine.

EDIT: That said, if anyone would like to compile a list here of possible extensions for which it would be safe for Scrivener to assume they are plain text, I could add them - .xml seems a good one to add to Scrivener’s native import list, I suppose, although it is not obvious as Scrivener is a writing tool and how many .xml files are you going to want to import?

Well, .tex seems an obvious candidate. But there might be dozens of types of code fragments and such that a non-fiction writer would want to import. I think there are just too many plain text extensions out there to make hard-coding them a comfortable solution. I concur with AmberV that the problem would better be handled by an ‘accept’ list managed by a user preference item.


PS: Merry Christmas, Keith, and a staggeringly prosperous new year.


I’m a software developer, so my writing needs are different than the majority of your users. Short of having a configurable “always treat as plain text” type of preference setting, it would probably be difficult to compile a comprehensive list of plain text extensions that met everyone’s needs. I’ll stick with the batch renaming approach.