Help on Script - Create bookmark with Item Link

I would like some helps on creating a script to automate a repetitive action which is to create a bookmark with the DT item link of a document.

I suppose the script would include following steps:

  1. copy the name and item link of selected document;
  2. create a bookmark;
  3. paste the item link to the bookmark URL;
  4. set the bookmark name to be the same as document name;
  5. [optional] mimic tags, label, flag status to the bookmark.

This is similar to creating Replicate. I try not to use Replicate, because I use Index database and I want to control the original file location.

I have no knowledge of Apple Script syntax, would appreciate to get some helps/hints to make this work. Thanks in advance!

The basic answer is

tell application id "DNtp"
	set theRecords to selection
	repeat with theRecord in theRecords
		set theDatabase to database of theRecord
		set theName to name of theRecord
		set theLink to reference URL of theRecord
		set theTags to tags of theRecord
		set theBkmk to create record with {name:theName, type:bookmark, URL:theLink, tags:theTags} in incoming group of theDatabase
		set label of theBkmk to label of theRecord
		set state of theBkmk to state of theRecord
	end repeat
end tell

The usual warning: changes made by scripts cannot be undone! This script works on selected documents. Test it with test documents. Start by selecting only one or two documents.

The bookmark is currently created in the inbox of the database in which the record being bookmarked is located.

@bluefrog I tried and failed to create the bookmark in the exact location of the record being bookmarked (specifically I used set theLocation to location of theRecord and set theBkmk to create record with {name:theName, type:bookmark, URL:theLink, tags:theTags} in theLocation of theDatabase but that doesn’t work; could you provide the correct way of addressing the location please? Then I could add a little more to the script. Cheers :))

2 Likes

I came here looking for something exactly like this so thank you for sharing @Blanc.

I have adapted the script to my needs but I haven’t been able to determine how to create the record in a specific group within the Database. Is it even possible?

It’s easy enough to do with a Smart Rule but I was hoping to avoid using another one as my sidebar is so cluttered with Smart Rules already.

It is. The complete syntax is create record with <properties> in <group> as described in the scripting dictionary. You can inspect it in the Script Editor by selecting “Scripting dictionary” from the “File” menu and then choosing DEVONthink 3.

Thank you for sharing this script @Blanc. It does exactly what I was looking to accomplish (specifically, adding the tags from the original record to the bookmark).

The location returns a string, e.g., /Inbox/Stuff.
Use location group as it returns the reference, e.g., parent id 5594 of database id 8 of application "DEVONthink 3

1 Like

Interestingly, for me it does seem to create the bookmarks in the same location but I haven’t tested extensively.

Edit: In my specific case, this seems to be related to groups not being excluded from tagging. While the bookmark is added to the inbox, it also receives all tags (including group tags) and is therefore replicated to the same location as the original files.

Thanks so much for helps! Your script works super well for my needs without even any change needed.

1 Like

This is interesting - I believe this would effectively be a way of Replicating items in different databases, something that cannot be done currently. Correct? [I realize there is only one original here and in “real” replicants all are originals. Still the functionality is there - and this is not possible presently across databases.]

1 Like

Yes, the bookmark would behave as Replicate. Essentially, it is a bookmark file with the Item Link that points to the original file. So this method is not limited across databases.

This works well in my indexing databases. I want to store only one original file, but also want the “replicated” file to be visible in the Files.app. By creating a bookmark it would be able to achieve.

1 Like