Need correct Applescript to move a file to specific group

I’m attempting to create a folder action to move a file external to DEVONthink into a specific group within an existing database. The database is named Financial and the group is CC Statements.

I just cannot come up with the correct syntax and would appreciate some guidance. Thanks…

This is certainly possible but have you looked into smart rules?

You could index the external folder into the Global Inbox and set up a smart rule to make such a move.

That’s what I have been doing; however, I have created 21 smart rules and will need many more…likely a total of 40 - 50. I’m having some issues with smart rules in that they will fire only when actions are performed every minute or on demand…and displaying banner notifications take forever to appear.

My thinking that 50 rules firing every minute DEVONthink is running is a bit of overkill. I’ve tried other triggers, but every minute is the only one that will work without my intervention.

Also, although I have no issues with notifications related to other apps…Hazel and Keyboard Maestro for instance…notifications displayed as part of a smart rule take forever to appear. Odd that the expected notification appears almost immediately in the Notification Center.

If smart rules worked better for me, I would abandon writing a folder action.

I have created 21 smart rules and will need many more…likely a total of 40 - 50.

What are you doing that requires so many?

but every minute is the only one that will work without my intervention.

Why the need for such constant running?

Good question! I download various financial documents where Hazel performs OCR if necessary and renames the file in the following format: yyyy.mm.dd - “name of financial institution”.pdf. A smart rule keys on part of the filename.

3AE6F186-2652-4D19-8E01-1BCE88D42270

I don’t need constant running, but it’s the only action that works automatically for me. I’m open to suggestions, but I’ve tried all the other obvious actions with no success.

So are you just anticipating setting up 20-50 folders with folder actions right now?

I’ve recently switched from Evernote to DEVONthink. Using Hazel I was able to use just a few rules to move files into the proper Evernote notebook.

I would use Hazel for the same purpose with DEVONthink if I could, but it doesn’t seem feasible. In order to have the same functionality with DEVONthink using smart rules, I’ll likely need up to 50 rules. Most rules will fire monthly; however, there are some which will do so quarterly…some annually.

To answer your question… No they don’t need to be created right now. I certainly can wait and manually move files when necessary.

yes it is possible. i do it. use Hazel to move the file to DEVONthink’s Global Inbox. From there DEVONthink will automatically import. set up a rule or rules which fire up “on import” (not scheduled) to do what you want to the files with the actions.

no applescript needed.

1 Like

It rekindled something I was experimenting with a bit ago. Something to help this kind of filing may be in the future. Need to discuss some of it with Development.

:slight_smile:

For some reason on import will not work for me. I wonder whether I might have a corrupted file somewhere.

Would you mind posting a screenshot of your Hazel rule? It would be very helpful…

night time here. will show an example tomorrow.

Sounds promising…

@rmschne mentioned the on import works in his rules. Can you think of something that might cause it to not function in my rules?

Thank you…

Smart rules aren’t triggered by AppleScripts but not knowing the rule in use, I can’t say if that’s it or not.

I do the exact same thing with hazel and DT, for account statements and some regularly arriving bills. Hazel can be scripted to sort the documents into the DT groups (and tag them, too).

See attached document which describes what I do in general-enough terms for you to consider.

DEVONthink and Hazel Productivity.pdf (1009.7 KB)

I would be very interested in the scripts you employ to move documents directly to DEVONthink groups. It would be very helpful if you could post just one as an example.

As you are likely well aware, moving documents into the proper Evernote notebook was quite easy using Applescript within Hazel. It was also nice to be able to change the creation and modification dates to agree with the statement date for easy sorting.

See my PDF posted earlier where I do just that with Hazel and DEVONthink. No AppleScripts. I didn’t elaborate on the Rules inside DEVONthink, but anyone doing rules can see how to do it and maintain them.

@rmschne, you have written the Bible for new DEVONthink users who have switched over from Evernote!! I cannot thank you enough for taking the time to write your very detailed document and sharing your knowledge.

I have read all DEVONthink documentation I could find, but the topic of the Global Inbox was completely missed. I must have missed it when my eyes glazed over while my brain was trying to absorb too much information. I gave it a quick try…as you mentioned it worked flawlessly with a smart rule set to fire on import. Perfect!!

I need to reread your document and follow-up on all the references you provided so I can really make DEVONthink work for me as it should. Again…thank you for sharing your knowledge and experience.

I posted a basic JavaScript here


and here

The first parameter is of course the file you want to move. The second parameter is the “selector” for the group: It indexes into the groupSelector object. In the example, it would be either “tag1” or “1234”. By adding more "selector": [database, group] lines to the groupSelector, you can provide for any number of groups here. I used the “database”, too, because I have identically named groups in different databases. So you might want to change that if you don’t need it.
I just use this one script for all of the Hazel rules that move things into DT: They call it as their last step providing the appropriate parameter.
I do not modify any dates for the files, though, but just add the statement date to the file name. Matter of taste, I guess.
Why do I do this with Hazel? Because in DT I’d need more smart rules. Hazel can process all account statements from the same bank with just one rule and I need only one script there to address all DT groups. So I’m handling three banks with a total of about 8 accounts with three Hazel rules and one script. I’d have to have eight smart rules in DT, which I find a bit uncomfortable. Also, I try to follow don’t repeat yourself :wink:
Alternatively, one could probably write an AppleScript for a smart rule in DT (JavaScript is not possible in DT smart rules, unfortunately). Since I don’t really like AppleScript, I didn’t try that.