Inconsistent results for "name of theRecord"

The command
set theName to name of theRecord
returns “whatevername” when the selected record is whatevername.pdf or whatevername.rtfd. But whatevername.eml returns “whatevername.eml” and whatevername.txt returns “whatevername.txt”. To get the base name for an .eml or .txt requires
set theName to name without extension of theRecord

Not an earthshaking issue – I suppose I could always use “name without extension” and it would work for any file – but I’d really like to understand why a record’s name may or may not include an extension. This kind of disparity I find baffling. It seems that if name always meant no extension (as filename presumably always means with extension), there would be no need for name without extension. Am I missing something here?

I vaguely remember a DT preference for file extensions. Did you check that out?

Were all these records imported recently using the same version of DEVONthink 3.x? Or are these older files imported using DEVONthink 2.x? DEVONthink 2.x had an import preference to name files either with or without extension.

All very recent, same version of DT (3.9). Some were imported, some indexed. Would that matter?

I have the setting to show file extensions enabled. Does this have any bearing on what those properties return?

I have so far only tested this with one or two files for each extension. I’m going to test more examples a little older (but still DT 3.9), both imported and indexed.

I have it set to show file extensions. Haven’t yet tried turning that off to see if it makes any difference.

How did you import them? E.g. via scripts?

All very recent, same version of DT (3.9).

So the problematic ones were recently added?

Some were imported, some indexed.

And the problematic ones are a mix of imported and indexed files?

Could be by using a script (emails), dropping a file in the Inbox, or creating a file in the Inbox.

Yes and yes. I probably need a larger sample.

Any rhyme or reason on the file format? You mentioned .eml, but does it also happen with, say an RTF, PDF, PNG, etc. ?

As noted in my original post, I found the same issue with a txt file, but not a pdf or rtfd. However, judging by further testing – so far only on eml records – my limited testing seems to have been misleading. Not all .eml files show this behavior. The method of importing the email makes a difference. Here is my interpretation of the processes:

  • Importing using a DevonThink Mail script builds a new database record from the data acquired by the script, and reconstructs the .eml file in DT’s internal file system from the information in the record. In this process, the script explicitly sets the name property to theSubject & “.eml” (I assume because otherwise DT doesn’t know what kind of record to create). Hence, name of theRecord returns subjectline.eml because the extension has been made an explicit part of the name property.
  • In contrast, dragging an email from Mail to the desktop and from there into the database Inbox appears to work in the reverse manner: the .eml file is filed directly into the DT internal file system, with the database record being created to match. There is no need to explicitly set an extension via the name property, so name is simply set to the subject property. Hence, name of theRecord returns subjectline, without the extension.

I suspect (but have not yet tested) that other file types may exhibit similar behavior depending on the way they are created and/or imported, e.g.:

  • txt/rtf files created within DT vs. externally in TextEdit or BBedit and then imported
  • PDFs downloaded via DT clipping extensions vs. Save PDF to DevonThink in Apple Print dialog vs. import to DT by Import Files & Folders or by drag-and-drop
  • files created internally by the various Data > Convert commands
  • files created by a script

All in all, it would seem to be safest to always use name without extension in scripts rather than just name, as there appears to be no easy way to tell how a given file will be named.

Most likely this issue is limited to scripts (as DEVONthink currently stores the name exactly as specified by scripts).