Smartrule for making unique link to open annotation file in obsidian

Dear Bluefrog,

Ik like the bi-directional links in Obsidian, it has an more intuïtive way of letting a second brain grow… for my little mind as psychologist I found it more easy to start this way. Devonthink is more robust, but you need to structure more… What I hope is that working on a mac, the different programs grow more to an easy exchange of data, so one can use the different forces in a constructive way…

DEVONthink’s link inspector shows both outgoing and incoming links?

And I’ve never had the link between an annotation file and the parent break. It seems like a good idea to figure out what’s going on there if it happens for you often.

But regarding Obsidian links… As I said, Obsidian core has no concept of a UUID. It looks like the Advanced URI plugin can create UUIDs for you, but if you want to automate this from DEVONthink, you probably have to define them yourself.

Here is an idea:

Use DT placeholders in your annotation template to constuct a uid based on date and time (YYYY-MMDD-hhmmss):

---
uid: %year%-%month%%day%-%hour%%minute%%second%
---

In a script you can either read this uid from the file directly, or build it again from the creation date of the annotation file. If you use DT4, reading it definitely seems simpler:

So, a smart rule script could look like this:

on performSmartRule(theRecords)
	set vaultName to "YourVaultName"
	set encodedVaultName to my encodeURIComponent(vaultName)

	tell application id "DNtp"
		repeat with theRecord in theRecords
			if (annotation of theRecord) ≠ missing value and type of (annotation of theRecord) = markdown then
				set theAnnotation to annotation of theRecord
				set theText to plain text of theAnnotation
				set theMetadata to get metadata of markdown theText
				set theID to |uid| of theMetadata
				set obsidianURL to "obsidian://adv-uri?vault=" & encodedVaultName & "&uid=" & theID
				set URL of theRecord to obsidianURL
			end if
		end repeat
	end tell
end performSmartRule

on encodeURIComponent(uri)
	run script "encodeURIComponent(" & (the quoted form of uri) & ");" in "JavaScript"
end encodeURIComponent

Though I think it makes sense to do it all in the same automation as renaming/moving.