Get Advanced URI for Note

I understand the Get Note Link returns an Obsidian URL that contains the explicit file path of the note. That’s fine to open the note later, but only if it has not moved within the vault. This might be fine for periodic notes that follow a specific convention for dated hierarchy where those notes are located (and probably won’t move). However, many other notes that I would like to link from OmniFocus and elsewhere move around at times, so this link will become invalid and unusable.

I know that I can get a link with unique UUID that will never change using the Advanced URI plugin. I can trigger the command “Advanced URI: Copy URI for current file” (or daily note), and that will automatically add an “id” property to that note and copy the Advanced URI to the clipboard.

So when I trigger that command, how do I retrieve the generated id from the properties to include in an OmniFocus note field. It seems that maybe I need to Get the Active Note, Get Note Properties (as a dictionary), and Set Variable for the key “id”. I did a little experimentation checking a note before and after the command, and sometimes it seemed to work, but I wanted to see what I’m really supposed to be doing for this common scenario.

It might be nice if the Get Note Link had an option to either get the Obsidian URL or Advanced URI.

Before answering your question, let me just state that you’re not the first person to ask for this, and I have looked into it. My plan is to add solid support for targeting notes by ID to one of the coming updates.

Now, here’s the answer. The note object contains the file properties already, so using Get Active Note should give you access to everything you’ll need:

That works when a note already has an id property. When it doesn’t have an id property, I can use Trigger Command for “Advanced URI: Copy URI for current file” that does assign an id property with a generated UUID as its value (and copy it to the clipboard).

However, after the command, I’m not getting the id property value, even if I use Get Active Note again, although I guess I could extract it from the the Advanced URI command in the clipboard, but I shouldn’t have to do that.

I thought maybe I need to wait for a little first before the note is updated so I tried 3 seconds but that didn’t make any difference.

How do I get a newly-assigned id property after issuing the Advanced URI command?

Ah, now I understand. Advanced URI doesn’t seem to save the file after inserting the UUID, so the file properties aren’t updated. Explicitly saving the file after applying the Advanced URI command does the trick.

Okay, that makes sense. I’m still a bit confused between Get Dictionary Value
using Get Value for id in Properties (from the Active Note), compared to Get Note Properties for Active Note in vault.

For some reason I don’t understand, if I select Properties in the Active Note thinking I will get a Dictionary doesn’t seem to work. However, if I use the Get Note Properties action, then I get the properties dictionary.

It seems they both return a Dictionary (which I tend to save in a properties variables, from which I usually save the value for a specific key after getting from the dictionary, since I may want multiple properties.

Also, what’s the difference between the Front Matter and Properties in a Note object. I’m assuming that the Front Matter probably returns the YAML as Text (including the “—” wrapper), whereas Properties returns a Dictionary with property key-value pairs.

Also, what’s the difference between the Front Matter and Properties in a Note object. I’m assuming that the Front Matter probably returns the YAML as Text (including the “—” wrapper), whereas Properties returns a Dictionary with property key-value pairs.

That’s correct. Should I make What is a Note object? more clear, what do you think?

For some reason I don’t understand, if I select Properties in the Active Note thinking I will get a Dictionary doesn’t seem to work. However, if I use the Get Note Properties action, then I get the properties dictionary.

Under the hood, both return JSON, because Shortcuts’ Dictionary object is just a JSON object. When a dictionary is transmitted between actions, that is done by storing a JSON string in a file. So the action can only hand out a proper JSON object as result, and Shortcuts decides how to handle it. If you want to play it safe, you can take such a result (JSON) and use it with a Get Dictionary from Input action, but Shortcuts is usually smart enough to turn it into a dictionary automatically.

Thanks for reminding me to review the Note FAQ since that helped somewhat. For example, you do mention that Front Matter does not include the “—” wrapper, although it’s not really clear if it’s a single Text value or a List of Text values. Also, it might be clearer that Properties is a Dictionary.

1 Like

I’ve added the types to the FAQ page.

I didn’t notice what you changed regarding types. They should be described using Shortcuts terminology: Text, Number, Boolean, List, Dictionary, List, or your custom type for Obsidian Note. Specifically, we need to know that Properties in a Note is a Dictionary, whereas Vault, File Path, Front Matter, and Body are all Text. This becomes important when using the value that you might save in a Shortcuts variable and what actions are appropriate to work with them.

You have a 404 Not Found error when clicking on “block of metadata” for Front Matter, whereas the “properties” link works fine.

When you updated the FAQ page, your new lines were eliminated. So the note is a single line, the front matter appears all on a single line, and there is no leading new line in the body. You need to reformat the page so it reflects what you actually see in a note.

Also it might be helpful to include a path for the File Path rather than showing an example for newnote.md in the root folder. For example, if you create newnote.md in a + folder, then it’s File Path would be “+/newnote.md” so it’s clear that it’s the file “path” and not not just its file “name”.

They should be described using Shortcuts terminology: Text, Number, Boolean, List, Dictionary, List, or your custom type for Obsidian Note.

Good point. Changed.

You have a 404 Not Found error when clicking on “block of metadata” for Front Matter, whereas the “properties” link works fine.

I hadn’t noticed Obsidian removed that particular page. Corrected.

When you updated the FAQ page, your new lines were eliminated.

Help Scout has a bug where the rendered file sometimes swallows the line breaks in those blocks. Annoying. Formatting is correct now.

Also it might be helpful to include a path for the File Path rather than showing an example for newnote.md in the root folder.

You’re right. Changed.

All good points, thanks for the input! :vulcan_salute:t3:

1 Like

It definitely looks much better, but there are still a few issues.

The leading new line is still missing from the Body (there is a blank line after the trailing “—” in the front matter (and that helps formatting the Properties block in the Obsidian editor also). You even mention it in your description, but it’s not there.

Your Note screenshot needs updating so it includes the Properties as well as Front Matter.

I wonder if it might be confusing that the properties of your custom Obsidian Note object contains a property called Properties, which is a Shortcut Dictionary that contains key-value pairs where each key is an Obsidian property with its value. So you would use the Note in a Shortcuts and select the Properties property rather than Obsidian Note, and then Get the Dictionary Value for the key with the Obsidian property whose value you want to use to set a Shortcuts variable. Perhaps a typical example that shows the sequence for accessing Obsidian properties might be helpful, along with some commentary.

I agree, the “properties/ Properties/ PROPERTIES” terminology has strong “Sunday, Sunday, Sunday!” vibes :sweat_smile:

The best idea I could come up with was using “Note object’s attributes” instead of “Note object’s properties” – I believe Apple themselves are using the term “properties” to describe a result object’s children but in the context of the page the variation is forgivable.

Regarding examples (again, good point!) I’ve pointed the reader to the example section of Get Note Properties; it’s a start, at least.

Yes, the examples in Get Note Properties do help.

I always wonder whether I should Get the Active Note and access the Properties, or use the Get Note Properties action.

When I launch a Shortcut from Obsidian, I use Get Active Note with Set Variable properties to Properties (in Obsidian Note), and then work Set Variable for specific properties that I want to use.

Get Note Properties doesn’t really offer any benefit except that it works with any file path, but that doesn’t seem to useful when I already have a Note object.

The Set Note Properties action also requires a File Path, which I suppose you can get the File Path in the active Note. If I create a Dictionary for Set Note Properties in some note, would I then have to Save current file so the changes are stored in Obsidian?

If I want to create or update a property in an active Note, I thought I would just use Get/Set Dictionary Value with the properties dictionary obtained from Properties in the active Note. Again it seems that I would need to Save current file so changes are stored.

Get Note Properties doesn’t really offer any benefit except that it works with any file path, but that doesn’t seem to useful when I already have a Note object.

That’s correct. If you already have the note object, you’re good. If you don’t and you are just interested in the file properties, use Get Note Properties.

The dictionary is just a local copy of what’s been returned when Obsidian was queried. It’s not a direct pointer to the original.

In regards to updating the file properties, Set Note Properties will auto-save the note so the changes are correctly propagated. So this would suffice:

Thanks for the clarification. It’s important to know that Set Note Properties does save the changes in the note, and the example is very helpful.