Ciao Luca,
As I said, it’s a JavaScript script, and yes, it is hand crafted. Sollid german engineeren, so to say .
It runs in Hazel and looks like this:
function hazelProcessFile(theFile, inputAttributes) {
var groups = {
"account1": ["database1", "UBI"],
"account2": ["database2", "Intesa"],
"account3": ["database3", "Banca Popolare 1"],
"account4": ["database3", "Banca Popolare 2"],
"tag1" : ["database2", "Expenses"],
"tag2" : ["database2", "Expenses"],
};
var app = Application('DEVONthink 3');
app.includeStandardAdditions = true;
var target = inputAttributes[0];
var dbName = groups[target][0];
var groupName = groups[target][1];
var db = getDBByName(app, dbName);
var g = app.search("name:" + groupName + " kind:group kind:!tag", {in: db});
app.import(theFile.toString(), {to: g[0]});
}
function getDBByName(app, dbName) {
return (app.databases.whose({name: dbName})[0]).root();
}
As you can see, I pass not only the current file (first parameter) to the script, but also a second parameter. This one depends on the file: if it’s an account statement, it is the account number. Otherwise, it is the tag set by Hazel previously, depending on the kind of receipt.
The script uses the data structure at the top to determine the DT database and group where the file is going to be added to. That permits me to use the same script in different Hazel tasks - they all use their own mechanisms to rename the file, extract information (to set the tag, for example) etc. In the end, they call this script with the relevant information and in the end, the file arrives in the correct group in DT.
I’m sure that this could be achieved with AppleScript as well. I’m just not as comfortable with it as with JavaScript.