Need correct Applescript to move a file to specific group

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.

Thank you, @chrillek, for your JavaScripts and explanation. Both you and @rmschne have provided some excellent ideas. I now have to do some research to decide which direction is best for my workflow.

Allow me to chip in, as I also recently left Evernote for DT3.

My workflow included Hazel monitoring an “Inbox” – mine is called “Action” – and applying it’s magic (I have over 200 rules), and then adding the file to Evernote, today DT3.

Below the simple AppleScript. I do not mind it being macOS only, because “once you go Mac, you never go back” ;-). Love my M1 Air btw, it is sssssooooooo snappy! My goodness. Gone are the days of getting my yearly new Air fix!

Anyways.

During my EN2DT3 migration, I wondered to leave Hazel in favour of DT3 Smart Rules combined with the Inbox. I chose to keep Hazel rules because Smart Rules can not be grouped in DT3, so that would become a very long list, as well as due to my familiarity with Hazel, not to forget DT3’s excellent support for AppleScript.

So. Here’s the magic.

--Script start
set DB to "yourDB"

tell application id "DNtp"
	
	--Pulling a Hazel output into strKN – optional of course
	set strKN to item 1 of inputAttributes

	--I'm not using groups as I'm a tag person, therefor need go to the root
	set destinationGroup to get root in database DB

	--theFile is a Hazel variable pointing the file being managed
	set newRecord to (import theFile to destinationGroup)

	--Adding all necessary tags, as well as imported ones
	set tags of newRecord to {"Hazel import", "yourTag", strKN}
	
end tell
--Script end

Enjoy

The M1 MacBook Air’s battery life is insanely good!
And the build quality feels more rigid than previous models. They always felt a bit flimsy to me but this one feels pretty solid.

1 Like

Thank you for the Applescript, @selsrog. I intend to experiment with it when I can devote some time.

I’ve heard nothing but excellent reviews of the new M1 laptops. Mine is a 2018 15" MacBook Pro i9 with 32 GB of RAM. It’s a real screamer, but I still want an M1!!

Oh… one more thing about the M1 MacBook…

My old friend… Yep, it’s back. The startup chime.
:heart: :heart: :heart:

2 Likes

I couldn’t get this to work and get error.

  • Is “yourDB” meant to be the name or ID of the database? I get an error trying both.
  • How do I change root to be Inbox or a specific group within target database? Given that I get error with script as-is, I have bigger issues first.

And which error might that be?

A fairly unhelpful one:

I’m finding more luck hacking this old thread. Given how obvious this operation seems, it is frustrating not to easily find an up-to-date resource explaining, with working example, a basic/generic script to import into a specific db/group.