Convert file types in RichText notes

I’ve used DevonThink for a long time and I love it, mainly because it stays out of my way, but when I want it, it does some quite clever things. However, there’s a use case that’s come along where DT leaves something to be desired. I keep a folder of rtfd documents which are records of pieces of music. rtfd is really handy because I can throw all sorts of media in there: screen-grabs of bits of music, audio files, links, all sorts. And I can annotate them in-line. However, I wanted to be able to share this stuff to my Android phone and I guess DT isn’t an option. So I tried EverNote, which is cool, but I found that I couldn’t easily transfer DT’s RichText docs to EN on the Android, because it wouldn’t display tiff files or pdfs in-line. My Android’s EverNote doesn’t have any trouble with png image files however, so I wrote this naive little python script to convert all the tiff images in my rtfds into png (convert works the same way for pdfs as well).

After that long-winded preamble, the question is this: I can’t find a convenient way to iterate through all the rtfd files in one particular DevonThink folder. All the notes are stored in the file system in different places. Does anyone know a way to get them all into the same folder, or maybe just get a list of all the paths of the files in a particular folder so that I can iterate through the list?


## I call this at the command line using `python -m`
## from within the rtfd's directory
import os
import subprocess
f = open("TXT.rtf", 'r')
txtfile = f.read()
f.close()

for x in os.listdir('.'):
    name,ext = os.path.splitext(x)
    if ext == ".tiff":
        print "converting %s" % x
        subprocess.call(["convert", x, name + '.png'])
        print "removing %s" % x
        subprocess.call(["rm", x])
        txtfile = txtfile.replace(name + ".tiff", name + '.png')
        
subprocess.call(["rm", "TXT.rtf"])

f = open("TXT.rtf", 'w')
f.write(txtfile)
f.close

Into the same folder in the file system, or into the same group in DEVONthink? (In this case it is useful to stick with the distinction DEVONthink makes – folders are for the file system, groups are for the database.)

If the latter – assuming you just want a list so you can run your script – would a smart group that finds the files help?

With that, you could export then to a folder in the file system, or move then elsewhere in the database, duplicate them, or whatever.

If it’s the file system you want to manipulate, then you could use a saved search in Finder and basically do the same operations in the file system – though that would wreck any indexing you’ve done in DEVONthink.

If you are referring to the internal structure of the database, you do NOT want to mess with it (unless you don’t mind jacking up your database). Seriously, don’t try to do it.

BLUEFROG

No, I’m not talking about the database, but rather the .rdfd files themselves which are stored in the file structure.

korm, Thanks, your suggestion to use the smartgroup constructor, or the search function gets me almost there. The results of the search can even display the paths, which is what I want. But I can display paths in the DT display of any folder anyway.
Screen Shot 2016-02-21 at Feb 21, 9.49.57 AM.png

But there doesn’t seem to be any way to copy those paths. If I copy any list of files in a DT display, all I get is the file names.

RTFD files are actually directories containing a variety of resources. If I can get a list of their paths, I can iterate through that list and act on the contents of those directories in place.

Any thoughts?

Jon

I’ll repeat the caution by BLUEFROG not to directly work on those files within the database without the “knowledge” of DEVONthink. At a minimum you will run into “missing file” errors and/or “orphan files”.

Suppose you find the Path of an RTF(D) file that’s stored inside the Files.noindex folder within the database, and write down that Path. Because, for performance reasons, DEVONthink dynamically moves such file locations, the Path of such a stored file might change at any moment.

Recommended: Work with Documents in the database (in the DEVONthink environment), not directly on their supporting files that are stored within the database. You will avoid a lot of grief by doing so. In the DEVONthink environment for a selected document, Data > Convert will provide some options, and Print as PDF will provide the option of producing a copy of the RTF(D) document as a new PDF+Text document (and its supporting PDF file). If you wish an image copy such as .PNG or .JPG, that can be done by taking a screenshot of the document, then capturing that screenshot to the database. If you wish to create of copy of the RTF(D) document contents as a Pages document, you could copy the contents of the document to the clipboard, then paste the clipboard into a new Pages document, save it and capture that file to the database. If you wish to capture an image contained within an RTF(D) document, select that image, copy it to the clipboard, then choose Data > New > With Clipboard and save it to the database (or a different database).

Thanks Bill_DeVille, for the crucial clarification:

I should have realized this myself. This is what I figured out: Export is what I want. I can Export copies of all the rtfd docs in a folder and then operate on the result (doh!) Thank you all for your patience, the feedback really helped me work out a solution.

So if I export the contents of my ‘Tunes’ folder in DT, the result is a folder of RichText documents sitting on my desktop. If I run this script from within that directory, all of the pasted .tiff and .pdf files in each of the .rtfds are changed to .png and the supporting TXT.rtf file is amended accordingly. The revised .rtfd files can now be dropped on Evernote and opened on my Android device where the pngs are displayed in-line. Just what I wanted.

Am I correct in thinking that currently DThink cannot do something like this: share some portion of a DT database with an android device via some kind of cloud service?


# this should be refined, but it does what I need
import os
import subprocess

for d in [x[0] for x in os.walk('.') if x[0].endswith('.rtfd')]:
    os.chdir(d)

    f = open("TXT.rtf", 'r')
    txtfile = f.read()
    f.close()

    for x in os.listdir('.'):
        name,ext = os.path.splitext(x)
        if ext == ".tiff":
            subprocess.call(["convert", x, name + '.png'])
            subprocess.call(["rm", x])
            txtfile = txtfile.replace(name + ".tiff", name + '.png')

        if ext == ".pdf":
            subprocess.call(["convert", x, name + '.png'])
            subprocess.call(["rm", x])
            txtfile = txtfile.replace(name + ".pdf", name + '.png')
    
    subprocess.call(["rm", "TXT.rtf"])

    f = open("TXT.rtf", 'w')
    f.write(txtfile)
    f.close

    os.chdir('..')


Not directly. If you have the files in a Dropbox folder that can be accessed on your Android device, you can index the files into your DEVONthink database.

Thanks BLUEFROG. Yeah, I was doing something like that with my Google drive, but the EverNote Android client is pretty useful in its own right. It’s a pity though, because it has none of the AI like features that DT has.