Updating tags in properties when copying notes between vaults

I have several vaults and I’m working on some shortcuts to help automate my workflows. For example, when I have a note that I want to share on my published vault, I add a note/share tag to the properties. I use a Dataview table query to create a list of notes in a Share List which I present so I can choose one or more that I want to copy between my private Ideaverse over to my digital garden vault where I can publish it when ready on my Obsidian Publish site.

It took me a while to work out how to process the Dataview columns in the query result, but finally I managed to get a list from which to make one or more selections. And I can Get Note from Ideaverse and Create Note in WarrenWeb, but I still haven’t figured out how to update the tags in properties for both notes. For example, I want to remove the tag that matched the query in the old note, so it doesn’t get selected again; but I want to add a different tag for note/wip to indicate it’s now a “work in process”. Also, I don’t want that old note/share to get copied over, but I do want to have the note/wip in the new note because I have another query in that vault to manage those WIP notes.

I have gotten tangled up trying to update Dictionary variables between the notes, but that hasn’t worked out. Also, I tried to Set Properties after Create Note in the target vault, but that didn’t work either. For now, I have to manually update the tags in both notes so they’re what I want using the Dataview query view notes. Obviously, I would prefer to automate updating the tags to reflect workflow processing. Any suggestions to get me unstuck?

Thanks, Doug Warren

Sorry for the delayed answer, @doug78645, but some stuff came up. :man_shrugging:t2:

Allow me to dive right in with an example. :slight_smile: Here’s Note 1.md:

---
tags:
- herp
- tag_from_note_1
- derp
---

My first note

You can get the properties of a note using Get Note Properties which returns a dictionary (key/value pairs). Assuming your note contains the standard Obsidian tags property, the dictionary will contain the tags key with a string list values (i.e., the single tags). So I’d first get the properties, then get its tags key. I’d create a new list from that key’s value, adding the new tag “note/wip” in the process, then store the value in a new variable Tags (since we want to manipulate the list, and having a variable around is easier to read):

This works because the built-in List action automatically “unwraps” every list you pass in, e.g. the Dictionary Value – so Tags now contains these items:

  • herp
  • tag_from_note_1
  • derp
  • note/wip

Now I can remove the undesired tags. To do that, I use Toolbox Pro, i.e. one of the Swiss Army knives of Shortcuts. I use Toolbox’s Filter List action for that. It lets me remove items from a list. Then I set Tags to the updated list:

Now Tags only contains these items:

  • herp
  • derp
  • note/wip

And now I can update the note using Set Note Properties. I’ll need a dictionary with the updated key/value pairs as an argument:

And now the example Note 1.md looks like this:

---
tags:
  - herp
  - derp
  - note/wip
---

My first note

That’s basically the process for both your notes. It’s not overly succinct, but that’s Shortcuts for you… :sweat_smile: I should probably think about adding actions for working with tags, I guess…?

Hope this helps!

Thanks for the great example. That really helps a lot to explain how to update the tags in a note. I don’t have Toolbox Pro on my old Intel iMac (it requires at least Apple M1), although I don have it on iOS. However, the Actions app has a similar action to remove an item from a list so I was able to use that instead. It took a little fiddling to get all the actions linked properly, but eventually I got it to work.

As you mentioned, I guess I would have to do this again for the note in the target vault. I’m still trying to decide whether I should simply copy the note to the target vault, remove superseded tags, and add any new tags and then delete the original note from the source vault (assuming that I want to actually move the note with updates).

Or I might copy the note and add new tags, while keeping the old one and probably removing and/or adding some tags (or possibly some other properties) since I probably want to indicate that it had been transferred and maybe when (date-time stamped). For example, if I make updates later in the target vault for my digital garden, and then eventually create a page or post on my website, then how do I reflect the changed note (and possibly other refactored variations) back in the original vault. I guess it is a version control and tracking issue, and obviously tI need to think about this more.

In my attempt, I was thinking that I would first get the note object, then update its frontmatter (tags), and then create a new notes in the target vault. I didn’t realize that maybe I should only use Get/Set Note properties directly on the note in both vaults. I noticed the Rename/Move Note action does not provide the ability to work between vaults (apparently, it only works in the same vault). And I didn’t see anywhere where I could copy or move a note between vaults (that might be nice). Also, I’m wondering whether updating properties works the same as tags, or can I work with the properties Dictionary from the Note.

Thanks for your help.
Doug

The fastest and easiest way to copy a note between two vaults is a combo of Get File and Save File:

For example, if I make updates later in the target vault for my digital garden, and then eventually create a page or post on my website, then how do I reflect the changed note (and possibly other refactored variations) back in the original vault. I guess it is a version control and tracking issue, and obviously tI need to think about this more.

This sounds like you might end up with a lot of duplicated notes across several vaults. Maybe replace the content of the original note with an obsidian:// link pointing to the new note in the other vault instead?

Also, I’m wondering whether updating properties works the same as tags

It does, in general. But not every note property (== dictionary value) is a list of strings, so adjust the dictionary accordingly, see the docs on Set Note Properties.

Oh, I forgot about the Get and Save File actions that use the file system rather than Obsidian like Get and Create Note. I understand what you describe in your example, but it’s not working for me. When I enter the source file path in the action, I get an error that it can’t communicate with the helper app; if I change that to a Text action with the file path and use that as the file path parameter for Get File, then Actions for Obsidian crashes. I also don’t see the New File Name parameter in my action, although I do have Create Folders option that you don’t show.

I wonder if I might be better off trying to do this with Run JavaScript for Mac Automation action with a JXA script inside the shortcut rather than a bunch of actions. Or maybe even Run Shell Script action with a ZShell, Node/JavaScript, Python, or Swift command.

I appreciate your comments about how to avoid duplicated notes, and perhaps using URI links might be better than actually moving the notes. I guess I might use something like a version property to help me deal with different versions of a note after it’s copied (and then changes).

In fact, it might get refactored in many smaller notes, so I might need to handle that somehow also. Perhaps, it would be better to include some version control or change log after a divider at the end of the note to help with this.

Obviously, I need to think about this much more since it raises so many questions and potential issues. Maybe it’s worth investigating how I can leverage Git to help with version control with my vaults.

I also realized that I would need to copy an referenced attachments for each note, such as images. How would I identify all the image links in a note so I could copy those along with the Markdown note file. Maybe I have to use a DataviewJS query to access the Dataview API with more options than simple a Dataview.

I appreciate all the feedback and suggestions.

Doug Warren

Ah, my bad – I’ve created the example with the just released Release 2024.2 (macOS & iOS)! Please update and see if it works with that.

I wonder if I might be better off trying to do this with Run JavaScript for Mac Automation action with a JXA script inside the shortcut rather than a bunch of actions. Or maybe even Run Shell Script action with a ZShell, Node/JavaScript, Python, or Swift command.

I guess it’d be quicker. If it’s any consolation, I’ve put “Add tags-related actions” on the project task list for 2024.3 :wink:

I updated to Actions for Obsidian 2024.2, but it’s still not working. When I try Get File with either the actual file path or a Text with the path, it sometimes crashes and other times it says it can’t communicate with a helper app. I tried replacing the existing actions in the shortcut with brand new ones just to see if that made any difference, but nothing changes. I have the current Actions URI 1.6.7 from several weeks ago.

I think tags actions would be useful since it’s a bit tricker to work with them currently with a bunch of Shortcut actions. Since the tags property in frontmatter can contain either a single tag, or a list of tags so I suppose it might be best to always return a list (even if it only has zero, one, or multiple elements). Perhaps the actions should focus on managing metadata properties (and fields), since tags is just another property. This might offer additional flexibility over simply working directly with the properties Dictionary in an Note directly in Shortcut actions. Also, any metadata for #tag or field::value can appear be inline as part of the body of a note, you might want to consider those.

I also wonder if it might be useful to include some actions that help manage sections (headings) and list items. Currently, I have to rely on DataviewJS mostly to get useful views based on metadata in list items.

Any suggestions about how to identify any attachment links in a note so those files could also be copied along with the Markdown note itself. Otherwise, that note will not render properly in the target vault without any referenced images. I suppose I could use JavaScript to extract any internal image links from a Note, and maybe even use JavaScript to copy them to the target vault, which might be more efficient that Repeat Each … Save File in Shortcut actions.

If Get / Save File won’t work, could I copy a Note using Get / Create Note as an alternative? Is there any advantage to use File vs Note for a Markdown file? I know one uses the file system rather than Obsidian for the copy, but what’s the significance of that difference?

Thanks for your help.
Doug

I updated to Actions for Obsidian 2024.2, but it’s still not working. When I try Get File with either the actual file path or a Text with the path, it sometimes crashes and other times it says it can’t communicate with a helper app.

I got reports that after updates to Shortcuts-enabling apps, a reboot did the trick because it cleared out old running app instances. It didn’t always solve all issues but it was a good first step. I suspect you’ve already tried that, though.

I tried replacing the existing actions in the shortcut with brand new ones just to see if that made any difference, but nothing changes. I have the current Actions URI 1.6.7 from several weeks ago.

I think tags actions would be useful since it’s a bit tricker to work with them currently with a bunch of Shortcut actions. Since the tags property in frontmatter can contain either a single tag, or a list of tags so I suppose it might be best to always return a list (even if it only has zero, one, or multiple elements). Perhaps the actions should focus on managing metadata properties (and fields), since tags is just another property.

That’s a really good idea, Doug, thanks!

Also, any metadata for #tag or field::value can appear be inline as part of the body of a note, you might want to consider those.

Yes, there’s a couple of details I need to take into account…

Any suggestions about how to identify any attachment links in a note so those files could also be copied along with the Markdown note itself. Otherwise, that note will not render properly in the target vault without any referenced images. I suppose I could use JavaScript to extract any internal image links from a Note, and maybe even use JavaScript to copy them to the target vault, which might be more efficient that Repeat Each … Save File in Shortcut actions.

No need for JS if you want to go the Shortcuts route. The note’s Body attribute/prop contains its full text, so you could use a native Match Text action to pattern-match the attachments. For example, I use the standard Markdown format for adding images and PDFs (e.g., ![[media.jpg]]), so the regex pattern for the Match Text action would be \!\[\[(.+)\]\]. Using it together with the built-in Get Group from Matched Text I get a list of clean attachment file names:

I’d follow that up with a Repeat block, looping over the results, prefix the items with the media/attachment folder’s path, and then copy the files over.

If Get / Save File won’t work, could I copy a Note using Get / Create Note as an alternative? Is there any advantage to use File vs Note for a Markdown file? I know one uses the file system rather than Obsidian for the copy, but what’s the significance of that difference?

The difference is that files are taken as-is (text, binary, any format – doesn’t matter) whereas notes are plain text “dissected” into their constituent parts, and come with metadata attached. And, as you mentioned, files are moved by accessing the file system; notes are handled using the API (currently…).

And yes, you could copy the note via Get Note from vault 1 – and use its Content attribute as the Note Body parameter of a Create Note action in vault 2.