ryanjamurphy/DEVONlink-obsidian

Is it possible to support revealing Obsidian notes from different vaults in DT?

Opened this issue · 7 comments

I have two vaults indexed in DT, one (Vault A) for desktop usage as the main vault and another (Vault B) for mobile usage as an "inbox" vault. I have set up Vault A as instructed such that notes within this vault can be revealed in DT. It would be great to be able to reveal notes in Vault B in DT, such that one can summarize/organize/move notes more efficiently between these two vaults in DT.

Do you mean from Obsidian → DEVONthink, or do you mean DEVONthink → Obsidian?

The former (Obsidian → DEVONthink, via the Reveal in DEVONthink command in Obsidian) should work already, I think, as long as filenames are unique. The algorithm works simply by opening the first DEVONthink record in any database that matches the filename of the current note.

If you mean the latter (DEVONthink → Obsidian, via the script here), you should be able to set up the script to do this... it would just mean adding an iterator to the script so that it checks both vaults for a match. I could look into this at some point.

For the first case, I tested to reveal a few more notes from Obsidian to DT. It might be related to the fact that there are Chinese characters in the file name. For example, I got the following error when trying to reveal the following note in DT:

Debugging DEVONlink. Failed filename: '利用捷径将代码片段和主题保存到iPhone端的Obsidian应用中 - 202106200121.md'.

I also tried to reveal a few other notes with shorter and mixed English and Chinese characters, and it succeeded. So, I am not certain if it is related to the fact of having Chinese characters in the long file name.

For the latter case, I have configured it with the script for one vault, and I was not aware that it is possible to make it for two vaults. In fact, I meant for the former case, but it would be excellent to be able to support also the latter case. 😃

Interesting. I have zero experience with supporting Chinese characters, so I don't think that's a problem I'll be able to solve on my own... I'm curious, though. If you run the following AppleScript, does it work?

tell application id "DNtp"
	set theRecords to lookup records with file "利用捷径将代码片段和主题保存到iPhone端的Obsidian应用中 - 202106200121.md"
	set theRecord to the first item in theRecords
	display dialog name of theRecord as string
end tell

The easiest way to use the script for multiple vaults is to simply download it again and set it up to refer to a second vault, the same way you customized it the first time!

If you run the following AppleScript, does it work?

I don't have much knowledge working with AppleScript. Did you mean running the script from the Script Editor? If so, I got the following error message: error "Can’t get item 1 of {}." number -1728 from item 1 of {}.

I also tried to reveal the note above from DT, and it can be opened correctly in Obsidian.

The easiest way to use the script for multiple vaults is to simply download it again and set it up to refer to a second vault, the same way you customized it the first time!

Great! I will try this and report back.

Yeah, that's right, run it from the Script Editor. And dang, that's weird. The error you pasted just means it failed to find any file with that filename.

So, I guess something about that filename gets messed up in AppleScript. I think it's probably a deeper issue than I can work on, in that case... Sorry!

I asked for help on the DT forum, and the suggested search method worked for me.

AppleScript cannot find DT items with filenames of mixed Chinese and English characters - DEVONthink / Automation - DEVONtechnologies Community

Specifically, the following code can let me find the desired note in DT:

tell application id "DNtp"
	try
		set theFilename to "测试Test.md"
		set theResults to search "filename:" & theFilename
		if theResults ≠ {} then
			set theRecord to the first item in theResults
			display dialog name of theRecord as string
		else
			-- do something, e.g.
			display dialog "No matches for: \"" & theFilename & "\""
		end if
		
	on error error_message number error_number
		if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
		return
	end try
end tell

Is it possible to combine this script/method with your script for DEVONlink?

Interesting. I didn't know you could use search to return a scriptable list of results. Sure, this would probably work. Let me look into it!