Vault list in alphabetical order

Just a simple fix when I’m using multiple vaults would be to sort them in an alphabetical order instead of recent opened. I use a lot of Vaults, so it gets messy over time. I have to use another Vault to create a MOC list of vaults. On top of that it opens a random (recently used) vault on the start. So it’s not the best solution.

For example I have a vault containing 1 000 tarantula species with the relation to each other and recent publications about them, that is a sub-vault of my animal species vault. It’s not often used, but I want it to keep separated for the graph view. When I use it, it gets on top of the list and a little bit later it gets lost on the list.

2 Likes

I second this. It is messy like this.

2 Likes

I had the same problem. I sorted the folders by name in the ‘obsidian.json’ file and adjusted the ‘timestemp’ (ts) accordingly.

The Python script that I used for sorting:

d = {
    "vaults": {
        "72fa90175c3aedd5": {"path": "/home/seas/Library/N Obsidian_Notes/N01 Computer Knowledge", "ts": 1699886911920},
        "ad02d3386a37e8ab": {"path": "/home/seas/Library/N Obsidian_Notes/N02 BetterLifeGmbH", "ts": 1699886938905},
....................................
    }
}

# Sort by the path
sorted_vaults = dict(sorted(d["vaults"].items(), key=lambda item: item[1]["path"]))

# Update the ts variables in ascending order
current_ts = 0
for key, value in sorted_vaults.items():
    sorted_vaults[key]["ts"] = current_ts
    current_ts += 1

# Update the original dictionary
d["vaults"] = sorted_vaults

# Replace ' with "
string_representation = str(d).replace("'", '"')

# Output of the updated string
print(string_representation)
1 Like

To clarify: is obsidian.json stored in the global settings folder? How Obsidian stores data - Obsidian Help

I tried something like this, but Obsidian seems to ignore the changes to my settings file. Then it overwrites it with its own timestamps.

I figured out the issue. I’m running Obsidian v1.8.10. The vault order is determined not by the timestamp in the map, but by the order of the keys in the map. So I had to adjust my script so instead of just setting the timestamp, it recreates the map so when I serialize to JSON, it keeps the new insertion order. Also the setting changes only apply to newly opened Obsidian windows so if I already have a vault open, I have to exit Obsidian and re-open it.

Here’s the nodejs script I used for mine. Just change configFilePath for your system:

const fs = require('node:fs');

const configFilePath = process.env.HOME + '/snap/obsidian/current/.config/obsidian/obsidian.json';
const configJson = fs.readFileSync(configFilePath);
const config = JSON.parse(configJson);
if (typeof config?.vaults === 'object') {
  const list = Object.keys(config.vaults).map((id) => { return { id, path: config.vaults[id].path }; });
  list.sort((a, b) => a.path.localeCompare(b.path));
  //  orders the vaults according to the order of keys in the vaults map, so recreate it
  const vaults = {};
  for (let i = 0; i < list.length; i += 1) {
    const item = list[i];
    vaults[item.id] = { ...config.vaults[item.id] };
  }
  config.vaults = vaults;
  fs.writeFileSync(configFilePath, JSON.stringify(config));
}