Is there a way to run a apple script upon importing a file?

I’m wondering if I can automatically run a script upon importing a file into devonthink? I know I can create a finder folder action, which will work for my use case, but was wondering if I could do it within devonthink the same way?

Here is what I am trying to do:

I use emacs org-mode to write requirements documents. I would like to drop an org-file into devonthink and then run a script to ‘convert’ the file into either a PDF or RTF using either emacsclient or pandoc.

Any advice on how to best achieve this?

Thanks in advance.

There’s no “automatically run script on import” feature – and you’ve already explored the triggered script option. You could

  1. Create a Folder Action – a new one made with Automator, or a modified one based on one of the folder actions included with DEVONthink – that would do two steps (a) the conversion, (b) the import. This is a bit tricky since Folder Actions sometimes race ahead and complete without waiting for the script to finish running.

  2. Use Hazel to watch a folder, do the conversion, then import to DEVONthink. This would entail embedded scripts in the Hazel workflow. There are some interesting Hazel examples in the forum’s history.

or you could use standalone script similar to the workflow that Hazel would do in option 2

I figure the way to do it would be to use org-mode’s built in export tools (C-c C-e), and then choose one of the built in options (markdown, ascii, latex, etc…). You can use the latex export to kick it to a PDF automatically (C-c C-e l p).