Link Obsidian with AdvancedURI Plugin

Because different apps might have different naming convention, we can’t ask them to put the url value to a specific url parameter name because they also need deal with x-callback-url from other different apps.

Ideally, the parameter name for url is “url” and the parameter name for title is “title”. But it is not always the case. If those parameters are not standard(“url” or “title”), we will append “urlkey” or “titlekey” paramter-value pairs to hook’s x-callback-url. So later, when Hook processes this x-callback-url action, it knows which parameter is for url and which parameter is for title.

That’s why I asked you to pass the whole url of x-success, including parameters, if there is any.

Thank you

1 Like

Ah, interesting. I released now the new version. With these changes

2 Likes

As stated on your website regarding Obsidian: Using Hook with Obsidian – Hook You say that Hook to New is not supported. Do you mean an uri, which creates a new file in Obsidian? My plugin does support this. So should we add that feature too? Obsidian supports this out of the box.

1 Like

Considering Advanced URI’s support on Daily notes, would it also be possible to achieve the following when hooking an item to a daily note in Obsidian?

  • The Markdown link of the item would be obtained.
    • In the case of PDF Deep Linking, the selected text together with the Markdown link of the PDF file would be obtained.
  • A new daily note would be created by using the corresponding daily note template specified in Obsidian, if the daily note does not exist yet.
  • The Markdown link would be inserted to the end of the desired header within the daily note.

Thank you! It works great! Due to a bug in the current release, it won’t work in the current release. We will have a new release.

Just one minor thing, I have a note with title “my notes 10”. In the x-callback-url, it is “my+notes+10”. Is it possible that it is encoded as “my%20notes%2010”?
hook://x-callback-url/setCurrentNode?urlKey=advanceduri&title=my+notes+10&advanceduri=obsidian%3A%2F%2Fadvanced-uri%3Fvault%3Dmergepbx-master%26uid%3D8a8563cf-637d-4685-a9aa-ae770a5e0faa&urlkey=advanceduri

Both should be valid, right? I’m using a provided URL class to easily add params. I can’t change the encoding for <space>. I doubt that it causes any trouble, if so I would have to do the things more manually.

Definitely not manually change the encoding.

If “my+notes+10” is ok, then no change is necessary.

Thank you

1 Like

Do you mean Obsidian’s new action?

It does create a new note. The reason currently Hook is not able to use is that Hook is not able to get the url of the new note. Also the new note’s title. Because sometimes the new note’s title is different than the one in the new action url, if the note name exists already.

Perhaps there is some misunderstanding. Please correct me if that’s the case,

If advanced uri plugin has x-callback-url support for this, that would be great. Could you please let me know its action name and the parameters?

Thank you

My plugin doesn’t provide it yet, but I’m open to add that too. What is Hook’s “default” behavior for already existing files? Should I return an error message via x-error callback? Do you pass a title, or should it just generate a new file with Obsidian’s default new file name?

1 Like

Hook’s behavior is the same, regardless of whether the file exists or not.
If a file exists, Hook expects Obsidian will create a new note with a different name, and pass the note url and title back to Hook in x-callback-url. If not, use the title Hook passes in to create a new file and pass the note url and title back to Hook in x-callback-url.

Basically, we are expecting something similar to Obsidian’s new action, and more. Hook will:

  1. Pass a note title to Obsidian without vault name, because Hook does not know which vault to use. Obsidian’s new action allows new note without vault name.
    https://help.obsidian.md/Advanced+topics/Using+obsidian+URI#Action+new

  2. Pass src link’s mark down link to Obsidian as note’s content. It seems users like this.

  3. Pass Hook’s x-callback-url to Obsidian. It will have some parameters. Obsidian appends the new note’s url and title to the url of x-success and generates a new x-callback-url.

The following is an example url that is used to create a new Craft note.
craftdocs://createdocument?title=mymetac.xcodeproj&content=mymetac.xcodeproj&x-success=hook://x-callback-url/link-to-new%3FurlKey%3Dlink%26src%3Dhook://file/9cxEDQk2M%253Fp%253Dc3JjL215bWV0YWM%253D%2526n%253Dmymetac%25252Excodeproj%26title%3Dmymetac.xcodeproj&x-error=hook://x-callback-url/link-to-new-error

And the following is x-callback-url from Craft
hook://x-callback-url/link-to-new?urlKey=link&src=hook://file/9cxEDQk2M?p%3Dc3JjL215bWV0YWM%3D%26n%3Dmymetac%252Excodeproj&title=mymetac.xcodeproj&spaceId=5da14827-8aef-4318-46f8-e11c8273acaa&blockId=3D4C4032-1619-400D-92B2-3EF82A6BAF8D&link=craftdocs://open?blockId%3D3D4C4032-1619-400D-92B2-3EF82A6BAF8D%26spaceId%3D5da14827-8aef-4318-46f8-e11c8273acaa

Ok I think I’m finished implementing (not published yet). The only thing I don’t understand is the src param.

Pass src link’s mark down link to Obsidian as note’s content. It seems users like this.

So src as file content, but isn’t content used for that?

Is it possible to use the param data instead of content for file content? That’s what I’m using currently everywhere.

Sorry for the confusion. I should say source link’s markdown link instead of saying src link’s markdown link. Any name of Obsidian url’s parameter is your call. I will use those names when I create a Obsidian’s url.

The src parameter in the example url is part of Hook’s callback url, just like urlkey parameter I mentioned in the previous posts. It will eventually be passed back to Hook so Hook can create a proper link between two documents.

Thank you very much for your quick action!

Sorry, I still don’t get src. What exactly is the source? Is it a link of the new created file (where I don’t see a difference to the generated advanceduri)? Or is it just the generated uri wrapped in a Markdown format [title](uri)?

Hook can create a proper link between two documents.

Which two documents?

“Hook to new” just creates a new file and gets the file’s link immediately back, right?

Sorry for the confusion.

When I say the source, I mean the document(or web page, etc.) from which the user invoke link to new action. The is one of the two documents I mentioned in the previous post. The other one is the newly created file.

That’s correct. That’s all Hook needs.

You don’t need touch src parameter in the Hook x-callback-url. Just pass the whole hook x-callback-url +new note’s url and title back to Hook.

Thank you

Ahh. The problem is, I don’t know Hook and don’t even own a Mac, so I can’t test Hook.
Released a new version. Please let me know if everything is working correctly.

Example: obsidian://advanced-uri?filepath=test&data=myDataToWrite&mode=new&x-success=https%3A%2F%2Fgoogle.com

  • data for file content
  • filepath for title
  • instead of hook-get-advanced-uri it’s now just advanced-uri

It works great!

I noticed that AdvancedURI Plugin return urlkey on HookSuccess:
urlkey: “advanceduri”

I have included urlKey parameter in Hook’s x-callback-url, so that can be taken out. Though it does not affect Link to new action.

Thank you!

This is fantastic, and we will update our script based on it, and we’ll update Using Hook with Obsidian – Hook. Thank you so much for helping Hook users get more out of Obsidian, and vice versa.

One last thing that would be super useful would be a method that returns the full (absolute) path of the current document in obsidian (a traditional file:// URL would do). This would be useful even without adding any special ID to the page. Ideally, this would be in Obsidian itself, but Obsidian doesn’t have such automation as far we know.

This would allow users to do lots of extra stuff with the resource via automation. In particular, Hook would be able to reveal the note in the Finder. Users could then communicate with macOS to do all kinds of things with the file.

Note to Hook users: in Hook’s new integration with Obsidian , and going forward, Hook will read advanced parameters (Terminal defaults) to determine which URL format to use. Most users won’t need to copy/paste scripts anymore. You’ll just need to set a Terminal defaults to get an alternative script.

An example of such url is file:///home/vinzent/desktop/obsidian-testing/2021-11-13.md, right?

How are spaces handled? Should I just include them eg. file:///home/vinzent/desktop/obsidian-testing/2021 11 13.md. Or encode too? But the slashes need to stay, so I have to only encode the file names and dir names?

Can we just include that information in the original obsidian://hook-get-advanced-uri url? So I pass not only the obsidian uri, but also the file url?

Yes

Since it is a value of a parameter, I guess the whole path needs be encoded, including slashes.

It is an excellent idea

Thank you

Encoding it in the whole uri for sure, but I was/am unsure for encoding the file uri alone.

From the following uri

obsidian://advanced-uri?vault=obsidian-testing&filepath=example%2520file&data=ss&mode=new&x-success=https%3A%2F%2Fgoogle.com

this is the callback url
https://www.google.com/?title=example+file+1&advanceduri=obsidian%3A%2F%2Fadvanced-uri%3Fvault%3Dobsidian-testing%26filepath%3Dexample%2520file%25201.md&urlkey=advanceduri&fileuri=file%3A%2F%2F%2F%2Fhome%2Fvinzent%2Fdesktop%2Fcoding%2Fobsidian-testing%2Fexample%2520file.md

You see I pass the file uri via fileuri.
Everything correct?

1 Like