Is there a way to insert a note from your open vault to an other closed vault?

I have seen that there is an ability to open another vault using Obsidian URI
[Format your notes - Obsidian Help](Look for Obsidian URI in the page)

“open notes in Obsidian either from another Obsidian vault or another program.”

So here’s my question: Is there any way to add a unique note from where you are in your current vault (open) to another vault (with or without the ability to describe where in that other vault you want to put it)?

Example: I frequently am working on a vault that contains a project of mine (working on a game). In doing research, I seek some real world information and sometimes I want to keep the content of a webpage I’ve discovered but I want to pull that data and put it into Obsidian in a second vault (that is going to be a knowledge vault of stuff all over the place but including a lot more context than what I need in my current vault).

So I would like to be able to create a note and then poke it into another closed vault without switching to that vault.

Is that possible now out of the box, possible with some (unknown to me) plug in, or not possible (hence a feature suggestion)?

To the best of my knowledge, if the 2nd vault is closed, Obsidian would not be able to effect it. As you noted, the Obsidian URI methods for a new note opens the 2nd vault on note creation. See: Using Obsidian URI - Obsidian Help

If this was something I was trying to accomplish for my setup (macOS). I would use either “Keyboard Maestro” or “Alfred” to run a shell script that does the heavy lifting.

After some more thought, this may be possible with the “Templater” plugin.

Something along these lines:

  1. suggester modal for choosing which note to copy/move
  2. suggester modal for choosing which vault to receive the new note
  3. finally, use node lib fs to copy/move

One question I have, can fs write a new file outside of the current node environment.

Sorry not to have included the info (because I did not think of a outside-of-Obsidian solution and thus didn’t think OS came into the picture) that I’m on Win 10.

I can see a security aspect to not being able to poke new notes into a closed vault, whereas pull could be allowable.

If there is no current feature to support this in Obsidian, I’d like it as an option in Obsidian assuming that the process of opening and pulling from a closed vault is not that much different than the process of poking a new unique note into the closed vault.

Someone else on Reddit’s /r/ObsidianMD pointed out you can use URI opens to open both vaults. Once I figure how to recolour my theme (or pick another) for the second vault, I could manage with that.

But I’d like to have the feature within Obsidian.

Relatedly (maybe):

I haven’t looked into my vault directories, but assuming that notes correspond to files, could I just slap the file in the vault directory and the vault would pick it up or be encouraged to find it somehow?

Absolutely … any file you move into an Obsidian vault directory, will be indexed the next time the 2nd vault is open.

1 Like

I’ve cobbled together a Templater script to move a note to a secondary vault. In my initial testing, it works well. One caveat…

The folder/directory path on the secondary vault has to be the same as the source file. For example, if you try and copy path/to/note and path/to is not created already on the secondary vault, the script will fail. There are ways to do some checking and create the folder, but that involves more than I want to invest. Having said that, this is a very useful script for my workflow and am glad to have figured it out.

Here is how I use this script. I created a note titled CopyNoteToOtherVault in my templates directory with the script code below. I setup a template hotkey in the Templater plugin settings. I then created a note titled CopyNoteToOtherVault LOG. This acts as a running log of all files that are copied. The return value of the script is appended to this note. You can see the return value at the end of the script. I have it returning an Obsidian URI, but you can customize however you like. Then, finally, I call the script via the command menu or hotkey.

:warning: NOTICE: This script copies files and will overwrite any file with the same title. Use at your own risk.

To first use, in the script, you must uncomment the line of code that copies the file.

change:
// fs.copyFile(
to:
fs.copyFile(

Edit and add your vault(s) to the myOtherVaults array.

Run the Templater script!

Here is a short demo video … using some demo vaults.

demo

Let me know how it goes. All feedback is appreciated.

<%* 
// array of full paths to other vaults
const myOtherVaults = [
	'/path/to/vault/vault-one', 
	'/path/to/vault/vault-two'
];
// node.js fs (https://nodejs.org/api/fs.html)
const fs = require('fs');
// callback for copyFile
function callback(err) {
  if (err) throw err;
  // console.log( '"' + myVaultPath + '/' + fileToCopy + "\"\ncopied to\n\"" + myOtherVault+ '"' );
  new Notice( '"' + myVaultPath + '/' + fileToCopy + "\"\ncopied to\n\"" + myOtherVault+ '"' );
}
const myPath = '';
// all files
const myFiles = this.app.vault.getFiles()
  .filter(f => f.path.startsWith(myPath))
  .map(f => f.path);
// current vault path
const myVaultPath = this.app.vault.adapter.basePath;
// suggester for file to copy
const fileToCopy = await tp.system.suggester(myFiles, myFiles, false, "Select the file to copy");
// suggester for destination vault
const myOtherVault = await tp.system.suggester(myOtherVaults, myOtherVaults, false, "Select the destination Vault");
// vault name only for Obsidian URI
const myOtherVaultName = myOtherVault.split('/').pop();
// copy file
// fs.copyFile(myVaultPath+'/'+fileToCopy, myOtherVault+'/'+fileToCopy, callback);
// return file link or Obsidian URI
// return fileToCopy ? `- [${fileToCopy}](file://${myOtherVault.replace(/ /g,"%20")}/${fileToCopy.replace(/ /g,"%20")})\n` : '';
return fileToCopy ? `- [${fileToCopy}](obsidian://open?vault=${myOtherVaultName.replace(/ /g,"%20").replace(/\//g,"%%2F")}&file=${fileToCopy.replace(/ /g,"%20").replace(/\//g,"%%2F")})\n` : '';
%>

Might take me a few days, but I will get back to you with results or anything I totally don’t get (which I’m hoping won’t be anything given your explanation).

I sincerely appreciate the effort. I’m glad you find the capability of use to yourself. And having it here, it might be useful for others later, which is the great part about these communities. Between here and /r/ObsidianMD, I have got a lot of great info just in the last 2 weeks on all sorts of aspects of the software (and CSS styling too).

Once I get a look at things (like Templater) and figure out the fine details of what your provided (probably by having script fails… lol), I may be able to help clean things up. I am a software dev on a good day.

I just have too many balls in the air (3 disabled folk in the house and a 15 year old) to spend the time I’d like plumbing the depths of Obsidian.

1 Like

No obligations whatsoever, duties 1st … your orig. post prompted me to figure out something I’ve been mulling over for a while, and for that I thank you. I’ve since then taken this and started creating a clone Vault widget. The idea is, you can copy your current vault’s settings, snippets, themes, plugins and have an empty vault with your current configured setup. Also, something I’ve been contemplating for a while. If you have any other questions on your “plumbing” adventures, please do not hesitate to reach out in a private message.

Roger!

That idea of being able to clone the vault (sans content) is pretty useful if you can sort it out.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.