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 :))

1 Like

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.