Is it possible to Export Files in Smart Rule?

Sorry if I have missed this in other posts but I am new(ish) to DEVONthink and wanted a simple smart rule to export the relevant tagged files into a specific macOS folder.

I can build the rules to find the files I want to export but can’t seem to find an action to export the files.

Can anyone point me to how I can do this?

The background to this, is that I have multiple devices running DT but want certain tagged files (PDFs) to be exported out of DT on an “always running” Mac, so that some other downstream processing by 3rd party apps & users can be performed.

1 Like

I didn’t find an action either. So I guess your best bet is a script in the smart rule

function onperformsmartrule(records) {
  const externalFolder = "Posix/Path/To/Folder";
  const app = Application("DEVONthink 3");
  records.forEach(r => app.export({record: r}, {to: externalFolder}));
}

That’s an untested JavaScript script. You could implement the same thing in AppleScript of course.

2 Likes

Thanks, I can see I need to add learn Javascript/AppleScript to the todo list :grinning:

So the exported files are distinct from the files in your database, i.e., you want to preserve the copies in your database?

Yes, I wanted to create a copy outside of the database for external use

1 Like

I would find this useful as well. There are things I need to make accessible to others via Dropbox. At the moment, I work on the DB folder, which is indexed in DT. It would be nicer to work in DT and have a smart rule exporting things, creating automatic copy of a group in an external folder.

@chrillek

That is an interesting and helpful tool to have in the script toolbox.

When I try to run it in Script Editor, I get an Undefined error - probably because I have not passed the selected DT3 records as the script parameter. How do I do that?

And are you as well talking about a copy, separate from your database, i.e., leaving your data untouched and in a different state than theirs?

Here is my use case: I have a database with scanned documents - pdf files for tax purposes (invoices, bank statements, receipts). When a new one comes in, it is renamed (smart rule with RE) and then (ideally) copied to an external folder (in Dropbox, same name of the group in DT). My tax advisor has access to the Dropbox folder. (With password it may require probably Keyboard Maestro?).

Initially, I manually copied the files from DT into the Dropbox folder. Then at some point it felt more convenient to scan directly to Dropbox (either with the Dropbox scan app or Readdle’s Scanner Pro apps workflows. For some time, I then indexed those Dropbox folders in DT.

When the indexing of the Dropbox folder and the smart rule for extracting dates and renaming caused problems, I stopped using DT for this purpose and deleted the tax database. Having an export of files, as a copy, would allow me to return to DT as the primary tool to manage this use case, having Dropbox as a secondary place to give people access to some files.

Yes. I want to keep the original file, typically a PDF, in DT. There is a capability in DT to export files or even drag & drop, so I assumed there would be a smart rule action to do the same.

Totally agree with this

undefined is actually not an error here but just the result of running the script. Since it does nothing …

As to your question: The function working on the current selection looks like the one below. It’s of course not very elegant to hard-wire the target folder, instead it could ask the user for it, at least in the stand-alone script.

(() => {
  const externalFolder = "Posix/Path/To/Folder";
  const app = Application("DEVONthink 3");
  app.selectedRecords().forEach(r => app.export({record: r}, {to: externalFolder}));
})()

There’s also this

Thank you @chrillek

Why does it say a Parameter is missing here?

Haha. Because I posted an untested script and @cgrunenberg was kind enough to read the documentation to me in the meantime. My bad.

The code in question should be

app.export({record: r, to: externalFolder})
2 Likes

@chrillek

That works. Thank you - much appreciated

Is there an equivalent to the Group selector to select a destination folder in Finder?

Is there an equivalent to the Group selector to select a destination folder in Finder?

For use in a smart rule?
We advocate smart rules and reminders should be headless and just quietly do their thing in the background.

Understood - my use at this point is building a library of “DT3 script snippets” to use as building blocks in future scripts - not necessarily in smart rules

var app = Application.currentApplication()
app.includeStandardAdditions = true
 
var fldr = app.chooseFolder({
    withPrompt: "Choose a folder!!!!!"
})
fldr

Riffed from Prompting for files or folders

2 Likes

Thank you - including the Apple Docs reference- that looks helpful for other uses too

And then there’s of course

1 Like