Exporting files attached to transactions

sarfaraz.dawoodi's Avatar


26 Oct, 2016 10:56 AM


For reporting purposes, it will save me hours if I can write a python script to export the documents attached to a specific set of transactions. This is because I always attach invoices receipts etc to my transactions and, for quarterly reporting, I need to send these documents to my accountant. It takes me hours to number them properly so that he can match up documents to transactions - doing this with a script will save me a lot of time.

I've got as far as getting the stored file name using:


but I'm stuck on getting the full path name of the file so I can do:

IOUtils().copyFile( File( <attached filed>) , File( target file> ))

I can see by looking in the Package Contents of my account book that it is

<path to my book>/safe/attach...

but I can't find any Python function which will give me that path. Or do I just have to hard-wire it?

In any case, if I do hard wire it, I can copy the files out but now I can't open them? I have given them the correct extension (all are pdfs) Do you compress them or something when they are stored? How do I get them out so I can open them?

The documentation for getAttachmentTag() says:

"Return the storage location, if any, that is associated with the given tag name. The resulting file can be retrieved by calling"

but it stops there?


  1. Support Staff 1 Posted by Sean Reilly on 27 Oct, 2016 08:37 AM

    Sean Reilly's Avatar

    Whoops, sorry about the documentation dropping off there. The method description should have continued with the following code:
    InputStream attachmentIn = transaction.getBook().getLocalStorage().openFileForReading(transaction.getAttachmentTag(tagName));

    The reason you have to go through the local storage rather than read the file directly is because the raw files are encrypted along with the rest of the data. So the openFileForReading(String path) method is needed to access the right file as well as decrypt it. In our attachments panel we read the encrypted file into a temporarily decrypted file in order to open it with the local storage's method readFile(String path, OutputStream tempFileOut).

    Good luck!


    Sean Reilly
    Developer, The Infinite Kind

  2. 2 Posted by sarfaraz.dawood... on 09 Jan, 2017 10:31 AM

    sarfaraz.dawoodi's Avatar


    Thanks for that - I got it to work in the end. One thing, though - you said local storage method readFile() - the method is readFromFile()

    best regards,


  3. System closed this discussion on 10 Apr, 2017 10:40 AM.

  4. sarfaraz.dawoodi re-opened this discussion on 07 Jul, 2017 06:23 PM

  5. 3 Posted by sarfaraz.dawood... on 07 Jul, 2017 06:23 PM

    sarfaraz.dawoodi's Avatar


    I got my export script working using this information but now it’s stopped after upgrading to MD 2017 (build 1597). The problem I get is this:

    AttributeError: 'com.moneydance.apps.md.controller.AccountBookWrapp' object has no attribute ‘readFromFile'

    when I do

    <txn>.getBook().getLocalStorage().readFromFile( <txn>.getAttachmentTag(<key>), <outstream> )

    any ideas? It’s like the method doesn’t exist on the LocalStorage class.

    Sarfaraz Dawoodi

  6. Support Staff 4 Posted by Sean Reilly on 07 Jul, 2017 07:09 PM

    Sean Reilly's Avatar

    Hi Sarfaraz,

    Ah yes! The readFromFile method was renamed to readFile, but should have the same parameters. Also, I just recently created a python script that will export all attachments from MD2017. I've attached that script here in case it might also help.


  7. 5 Posted by sarfaraz.dawood... on 07 Jul, 2017 08:07 PM

    sarfaraz.dawoodi's Avatar


    Great! That worked! Will you update the online API documentation? Is there any way I could have figured that out? Is there a way of listing the methods of a class within a python script? If I could do that I would probably have been able to figure it out myself.

    many thanks and best regards,


  8. System closed this discussion on 06 Oct, 2017 08:10 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac