Use x-devonthink-item to open item's Aliases

I am familiar with using UUID to open a Devonthink item from another application. Is it possible to do the same using Aliases?

I am on macOS. If a URL command cannot do it, can a simple AppleScript accomplish the goal?

Thanks.

Only UUIDs can be used to open items and only UUIDs will always work (e.g. independent of name, location or database of an item). A script could theoretically use aliases but it would be really slow (as aliases aren’t searchable the complete database(s) would be have to be scanned).

Thanks for the quick response. I thought since Aliases can be used in internal wiki-style links, there might be a look-up scheme that DT utilizes to quickly find the target of the link. The AppleScript would then utilize that same look-up scheme.

Aliases are basically only used for Wiki linking and for tagging. But linking that way wouldn’t be reliable. Why do you actually want to use them that way?

It’s a long story, and might be a fringe use-case. Briefly, my DT Aliases are BibTeX citation keys. I write in LaTeX and other text-only formats (e.g., markdown) in applications such as emacs or Drafts app. It would be convenient to select a citation key and quickly open the associated PDF in DT.

p.s. edit: as I think about it, perhaps it is not such a fringe use-case.

This little example script opens the document whose alias is equal to the contents of the clipboard:

tell application id "DNtp"
	set theKey to the clipboard as string
	if theKey is not "" then
		set theContents to contents of current database whose aliases is theKey
		if (count of theContents) is 1 then
			set theRecord to item 1 of theContents
			open window for record theRecord
		end if
	end if
end tell
1 Like

wow, that was super fast! Thank you so much.

Chris, just one more question: this didn’t work for me here and I think it is because the alias I am looking for is one alias and not all the aliases for the record. Could this be adapted to find an alias that is one among others for a specific record?

A single line can’t handle this - you would have to iterate through all contents, get their aliases, split them into components (actually separated by both , and ;) and then compare each component to the desired alias. This would be way too slow (really slow :slight_smile: ).

A simple but not precise change would be to replace whose aliases is theKey with whose aliases contains theKey

This is what I thought, but there is a problem: if the alias is 43a1, for example, then it will match 243a1, 343a1, 443a1, and so on. Would it be simpler/faster to just use the search command or perhaps with matches instead of contains?

That’s exactly the shortcoming I described as “not precise” above :slight_smile:

The search command doesn’t support aliases nor does AppleScript support matches.

Assuming that you always use , as the separator, then another workaround might look like this (untested):

	set theContents to contents of current database whose aliases is theKey
	-- Looks for alias as the beginning or middle
	if (count of theContents) is 0 then set theContents to contents of current database whose aliases contains (theKey & ",")
	-- Looks for alias at the end
	if (count of theContents) is 0 then set theContents to contents of current database whose aliases contains (", " & theKey)

Thanks, Chris. I will give it a try :slight_smile:

:frowning: I could swear that set theResult to search "aliases:" & theKey would work!

Mea culpa :stuck_out_tongue_closed_eyes: Of course it does in the latest releases… way too many features obviously :slight_smile: But the matches condition isn’t supported, only is/contains/ends/begins etc. Therefore aliases==... would be an alternative to the first script.

1 Like

Aha, I was not misremembering after all :relaxed: