# Hazel rule script for importing/indexing to a specific group

**URL:** https://discourse.devontechnologies.com/t/hazel-rule-script-for-importing-indexing-to-a-specific-group/15941
**Category:** Automation
**Created:** [July 1, 2013, 9:41am UTC](https://discourse.devontechnologies.com/t/hazel-rule-script-for-importing-indexing-to-a-specific-group/15941 "2013-07-01T09:41:55Z")
**Posts on this page:** 1
**Showing post:** 1

<div class="post-metadata">

### Author: ![korm](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/k/e0b2c6/32.png) [@korm](https://discourse.devontechnologies.com/u/korm)
#### Post date: [July 1, 2013, 9:41am UTC](https://discourse.devontechnologies.com/t/hazel-rule-script-for-importing-indexing-to-a-specific-group/15941/1 "2013-07-01T09:41:55Z")

</div>

The script in this posting is deprecated. Scroll down this thread and see the updated script dated July 10, 2013 – five posts below this one

See these topics:

> [@Revisiting Hazel](https://discourse.devontechnologies.com/t/revisiting-hazel/13973/1):
>
> Hazel has been discussed a few times previously. Apparently Hazel now has the ability to recognize OCR’ed text. I did not know this, and would like to reconsider using Hazel in conjunction with DTPO. So, if anybody has any experience with this combination, a few questions: If I ScanSnap items and OCR them into my DTPO inbox, can Hazel move items out of the Inbox? Can Hazel recognize the Sorter, or otherwise move files into DTP so that they are appropriately imported? Thanks!

> [@Using Hazel to move folder contents to Devonthink 2 Inbox](https://discourse.devontechnologies.com/t/using-hazel-to-move-folder-contents-to-devonthink-2-inbox/9885/1):
>
> I’m using Devonthink 2 (not Pro). I’m trying to set Hazel to move documents I have OCRd w/Acrobat into the Devonthink Inbox. What folder do I tell it to move them into? I can’t seem to find the inbox folder.

> [@import directly into group (skipping inbox)?](https://discourse.devontechnologies.com/t/import-directly-into-group-skipping-inbox/15938/1):
>
> Is it possible to import a .pdf file directly into a group within a database, skipping the ‘inbox’ of the database via scripting? I’d like to use Hazel to move certain files directly into the groups that I’ve set up in DevonThinkPro Office, rather than moving them all by hand in DT. Thanks for any advice. Jeff

Script to include in a Hazel (3.x) rule to import or index files (or folders) to DEVONthink (2.x). Applies concepts developed by [itaiferber](http://itaiferber.net/archiving-files-with-hazel-and-devonthink.html) and Greg Jones.

Modify the DEVONthink “tell” block:

1. Obtain the filesystem path for the target database and insert it in place of leaving the quotations: for example “~/Documents/Databases/My Stuff.dtBase2”
2. Enter the group path (starting at the database root – which is “/”), in place of leaving the quotations. For example “/Imports/My Hazel Docs/”
3. To import, use the command line beginning “set theImport…”
4. To index, use the command line beginning “set theIndex…”
5. Be sure to comment out either #3 or #4 depending on the method, else you will have an undesireable result.

The script will create the group with the given path in the database. If the group already exists, the existing group will be used and a new group will not be created.

WARNING: This script has to have correctly hardcoded database and group paths. If the paths are wrong or the database and/or the group is moved, the script will fail.

```auto
-- Get file metadata from Finder.
tell application "Finder"
	set _path to (the POSIX path of theFile as string)
	set _name to (the name of theFile as string)
end tell

-- Lauch DEVONthink if it isn't already open.
tell application "System Events"
	if not (exists process "DEVONthink Pro Office") then
		tell application id "com.devon-technologies.thinkpro2" to activate
	end if
end tell

-- Import the file.

tell application id "com.devon-technologies.thinkpro2"
	set theDatabase to open database "<DATABASE PATH>"
	set theGroup to create location "<GROUP PATH>" in theDatabase
	set theImport to import _path name _name to theGroup
	-- set theIndex to indicate _path to theGroup
end tell

```

It’s advisable to have Hazel delete items after they are imported – but do NOT have Hazel delete indexed documents 😕

---

_[View the full topic](https://discourse.devontechnologies.com/t/hazel-rule-script-for-importing-indexing-to-a-specific-group/15941)._
