Retrieve a folder location as a text string

I’ve created a database containing physical filing locations for important documents where a scanned copy is not acceptable. I would like to retrieve the location information from the info panel to use as a tag - basically as a text string - so I can create labels and tags from it for refiling purposes.

As a simple example of a location:

File Cabinet > Upper Drawer > Autos > Sprinter

Any thoughts on how to do this would be appreciated. The information in the View:Column:Location is read-only as is the info panel location. Is this information accessible via scripting?


The “location” property of a DEVONthink database record is the logical path (i.e., group hierarchy) from the database’s root to that record. In other words, it’s the database’s where’s-waldo for that record. Location can be set in your script - doing so will move that record to that location in the database. Location has nothing to do with the physical world in your office.

Using your example, if you set “location” for a record to “file cabinet\upper drawer\autos\sprinter” you’ll wind up creating four database groups with those names (starting at the root), and putting that record into the “sprinter” group.

Now, that’s not such a bad approach. It gives you, visually, a map to the place in the world where the thing might be. This approach could also work in the “Tags” group: to indicate physical-world location, you might want to consider using a tags hierarchy. There are several posts on this topic - search “tags hierarchy” in Advanced Search.

Thanks, that’s helpful as are the scripts in the resulting search you suggested. I am just learning Applescript, but do see the location property in the DTP dictionary.

It seems that it would be helpful if DTP allowed creation of tags without a cognate DB entry (unless I missed this feature) as well as conditional tag lists (e.g., filing cabinet only allows upper or lower drawer…, etc.


Tags in DEVONthink are actually groups. When a tag is assigned to document, the group for that tag inside of “Tags” contains a replicant of the document. (The terminology here is a bit odd compared to what many people are familiar with from other tagging methods.)

In the Tags group, you can create as many tags (i.e.,) groups as you wish – without connecting the tag to a specific record. Just use Data > New > Group. Tags can be nested, also. If you have these tags (groups):

–Filing Cabinet

I think you will get where you want with your example.

Following up on my question, here is an Applescript that retrieves the location of selected records and adds the location of groups as a tag. Appreciate any corrections. I don’t know how to add the nifty Select all option and the box.


--Convert Location to Tag
--Created by John A. McDonald 12/06/2011

tell application id "com.devon-technologies.thinkpro2"
		set these_records to the selection
		if these_records is {} then error "Please select some records."
		repeat with this_record in these_records
			set this_record_location to the location of this_record
			if this_record_location is not "" then
				set tags of this_record to (tags of this_record) & this_record_location
			end if
		end repeat
	on error error_message number error_number
		if the error_number is not -128 then display alert "DevonThink Pro" message error_message
	end try
end tell
1 Like

It would be helpful if one could select just records (e.g., not groups, not tags) but all documents, images, etc. I can’t find a good example of this, other than selecting them and then acting upon them. Any scripting gurus out there point me to a method?

Also, how do you create those neat select all script boxes?

Thanks, John

When posting scripts to the forum, click the Code button (see the picture below).

Place your script inside the "```

It would be helpful if one could select just records (e.g., not groups, not tags) but all documents, images, etc. I can't find a good example of this, other than selecting them and then acting upon them.
Not entirely sure what this means, but to select a record click on it.  (Three-pane view works best for this.)  To select multiple contiguous records, select the first one, hold the mouse and drag across the rest of the records you want to add to the selection.  To select multiple non-contiguous records, select the first one, then command-click each of the other records you want to select.  If you want to collect records of a particular type (e.g., images) using a smart group and then select the records found by that group, you can do so and run your script against that selection.  And so forth...

Thanks I’ll use the code box from now on.

I want to access records (documents, images, etc.) from a script, not manually. The reason is that in the script above, if I delete the record (e.g. a pdf file) the tag remains. If I move a record to another group or filing location, the old tag should be replace with a new one. It makes more sense to me to be able to select all records, and then run the above script against them. This would be tough manually given the way I have groups set up. Basically I want to exclude groups, tags, smart groups, and just select the records.


You’re describing a rather complex script.

Did you know that DEVONthink can automatically create tags based on group names? Perhaps reading the “Tagging” topic in Help (and the related topics mentioned on that help page) might give you some advice that could accomplish what you’re trying to do, but without needing to write scripts.

(I have to admit, sorry, that I don’t quite understand what you’re trying to accomplish – entirely my own inattention :cry: )

Yes, I do, thanks. It is complex. Lets say I have a set of hierarchical groups as follows:

File Cabinet > Upper Drawer > Autos > Sprinter

The last group is the name of a file folder, the rest just pointers to the location of the folder and documents (records) therein.

If a record(s) are selected, and the above script run, it adds the tag:

/File Cabinet/Upper Drawer/Autos/Sprinter

This is most helpful if you want e.g. to refile a document or are OCD.

But, if I delete the record, or move the record (e.g., I change filing systems, etc) the old tag remains. I want a script function that just selects all records so I can rerun the script.

Hope this is clearer… John

So here’s what DEVONthink can do without scripting.

This is one folder structure with a record:

If you have set your datbase settings to tell DEVONthink to make a tag for each group (File > Database Properties > Name of Your Database), such as in this picture (i.e., “Exclude Groups from Tagging” is not checked):

Then, you’ll see that the Sprinter Invoice document has these tags (look at the tags bar below the document preview)

The gray tags are groups, the blue tag is what DEVONthink calls a “normal” tag – i.e., one that I assigned manually to Sprinter Invoice.

Now, I move Sprinter Invoice’s location in the physical world to a file folder in the wire inbox on top of my desk, and so I move the record in the database to the Sprinter subgroup in my Desktop group, like this:

Looking at the tags bar, I see that DEVONthink has updated my tags automatically, and they now look like this:

The blue “Invoices” tag remains as it was (I didn’t change it) and the gray “group” tags have been updated automatically to reflect my current location. You’ll notice that the gray “group” tags don’t appear in the database’s Tags group - they don’t need to because DEVONthink is considering every group location in the database that has a yellowish folder icon to be a tag.

If the folder icon is blue, then that group has been excluded from tagging (control-click the group and click “Exclude from Tagging” in the contextual menu). For example, I’ve now added a group “March 2012” to my hierarchy, and excluded that group from tagging:

Because “March 2012” was excluded, it does not appear in the tags bar:

By the way, the sequence of gray tags in the tags bar always reflects the sequence of that group’s hierarchy. Even if you move one of the gray tags by dragging it in the tags bar, it will spring back to it’s proper location in the group hierarchy as soon as you select that record again. DEVONthink automatically creates group tags for all the yellow-icon groups containing the record, all the way back to the database’s root.

I hope the demonstration above shows that DEVONthink’s in-built tagging behavior can get this result for you without scripting. Good luck.

Very helpful! Thanks.