Disclaimer
Is this project open source? Yes
Is this project completely free? Yes
Is this project made with AI beyond the author’s ability to comprehend how it works? No
Title: Knowing who reads a shared vault (from the OneDrive account), and opening each person on their own note at start
Our small team (about a dozen people) shares one vault through OneDrive for Business. Each member has a person note with an Email property, and a dashboard at the top of that note. Obsidian has no notion of a user: it opens a folder. But the OneDrive desktop client on each computer knows very well who is signed in. So we read that account, match it with the Email of exactly one person note, and use the result for two things:
- Discretion: a few sections and buttons show only to the people whose role gives them the right (a section of the dashboard for the manager, the decision buttons of our portfolio review). Not security, everyone can still read every note and every script, but it keeps screens uncluttered and avoids “who clicked that?”.
- Starting on your own note: when Obsidian starts, each person lands on their own person note (hence their dashboard), alone, instead of the shared home canvas. A computer that cannot tell who sits there simply opens the home canvas, as before.
I did not find this approach described anywhere (the closest are the feature request Expose user identity for Sync login, plugins that sign in to Microsoft Graph, or typing one’s email in a plugin’s settings), so here it is, in case it helps other teams on OneDrive.
1. Reading the OneDrive account
Windows. The client writes each account in the registry: HKCU\Software\Microsoft\OneDrive\Accounts\<Business1, Personal…>, value UserEmail. A reg query from Node is enough (Obsidian’s desktop app exposes require).
macOS. No registry. Two findings from read-only probes on two Macs (November 2026, the standalone OneDrive app, not the App Store one):
- Do not read OneDrive’s group container (
~/Library/Group Containers/UBF8T346G9.OneDrive…): macOS then asks “Obsidian would like to access data from other apps”. Nobody should meet that prompt when a window opens. ~/Library/Application Support/OneDrive/settings/ListSync/Business_<id>/Microsoft.ListSync.Settings.dbis not protected, and its tablegeneral_settingshas a keyAccountHintwhose value is the account’s address alone. One folder per work account (it was namedBusiness1a few weeks earlier, so do not hard-code the name). Read with macOS’s ownsqlite3, the database opened read-only and immutable: nothing written, nothing locked, about 30 ms.
This is Microsoft’s internal storage, undocumented: it may move again. The code below then falls back to “not recognised”, which should always be a harmless state.
// Who sits at this computer: the work accounts of the OneDrive desktop client.
const DOMAIN = "@example.com"; // your organisation's domain
function windowsAccounts() {
const { execFile } = require("child_process");
return new Promise((resolve) => {
execFile("reg", ["query", "HKCU\\Software\\Microsoft\\OneDrive\\Accounts", "/s", "/v", "UserEmail"],
{ windowsHide: true, timeout: 4000 }, (err, stdout) => {
if (err && !stdout) return resolve([]); // no OneDrive account at all
const emails = String(stdout).split(/\r?\n/).map((l) => l.trim())
.filter((l) => /^UserEmail\s/i.test(l)).map((l) => l.split(/\s+/).pop().toLowerCase());
resolve([...new Set(emails)].filter((e) => e.endsWith(DOMAIN)));
});
});
}
function macAccounts() {
const fs = require("fs"), os = require("os"), { execFile } = require("child_process");
const root = os.homedir() + "/Library/Application Support/OneDrive/settings/ListSync";
let dbs = [];
try {
dbs = fs.readdirSync(root, { withFileTypes: true })
.filter((e) => e.isDirectory() && /^Business/i.test(e.name))
.map((e) => root + "/" + e.name + "/Microsoft.ListSync.Settings.db")
.filter((p) => fs.existsSync(p));
} catch (e) { return Promise.resolve([]); } // no ListSync folder: nobody
const uri = (p) => "file:" + encodeURI(p).replace(/\?/g, "%3F").replace(/#/g, "%23") + "?immutable=1";
const hint = (db) => new Promise((resolve) => execFile("/usr/bin/sqlite3",
["-readonly", uri(db), "SELECT value FROM general_settings WHERE key = 'AccountHint';"],
{ timeout: 4000 }, (err, out) => resolve(err ? [] : String(out).split(/\r?\n/))));
return Promise.all(dbs.map(hint)).then((lists) =>
[...new Set(lists.flat().map((l) => l.trim().toLowerCase()).filter(Boolean))].filter((e) => e.endsWith(DOMAIN)));
}
// The reader's person note, or null (nobody, or several notes: not recognised).
async function whoReads(app) {
const accounts = process.platform === "win32" ? await windowsAccounts()
: process.platform === "darwin" ? await macAccounts() : [];
const notes = app.vault.getMarkdownFiles().filter((f) => {
const fm = app.metadataCache.getFileCache(f)?.frontmatter;
return fm?.Type === "person"
&& [].concat(fm.Email ?? []).some((e) => accounts.includes(String(e).trim().toLowerCase()));
});
return notes.length === 1 ? notes[0] : null;
}
We keep this in one ES module, read once per session, imported at call time by every script that needs it (we use JS Engine). The rights themselves live on role notes (a Grants list), so a script asks “does the reader hold the right X?”, never “is the reader called Y?”.
2. Starting each person on their own note
The vault keeps its Default file to open (Settings › Files and links), a home canvas. A startup script (JS Engine’s Startup scripts, or onLayoutReady in a small plugin) replaces it with the reader’s note.
The one trap is a race, which I only understood by reading Obsidian’s startup code: Obsidian restores the workspace, runs the layout-ready callbacks (where startup scripts begin, without being awaited), and only then opens the default file in the active tab. So a startup script may run before or after the home canvas appears. The script waits for the default file to be the active tab, replaces it there, and watches for a few seconds in case it is opened again over the landing.
// Land the recognised reader on their own note, alone, in place of the "Default file to open".
async function landOnOwnNote(app) {
const ob = String(app.vault.getConfig("openBehavior") ?? ""); // e.g. "file:Home.canvas"
if (!ob.startsWith("file:")) return;
const start = ob.slice(5);
const note = await whoReads(app);
if (!note) return; // not recognised: keep the home file
const fileOf = (leaf) => leaf?.view?.file?.path ?? leaf?.getViewState()?.state?.file;
const active = () => app.workspace.getMostRecentLeaf(app.workspace.rootSplit);
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
// Obsidian opens the default file after the startup scripts: wait until it is the active tab.
let leaf = null;
for (let t = 0; t < 8000 && !leaf; t += 100) {
if (fileOf(active()) === start) leaf = active(); else await sleep(100);
}
if (!leaf) return; // the person is already elsewhere
await leaf.openFile(note, { active: true });
// Only that note in the main area (sidebars and pop-out windows untouched).
const others = [];
app.workspace.iterateRootLeaves((l) => { if (l !== leaf) others.push(l); });
others.forEach((l) => { l.setPinned(false); l.detach(); });
// If the default file opens over the landing a moment later, land once more.
for (let t = 0; t < 4000; t += 200) {
await sleep(200);
if (fileOf(leaf) === start) { await leaf.openFile(note, { active: true }); break; }
}
}
What to know before copying this
- Discretion, not security. Anyone can edit the scripts or the notes. We use it to show the right things to the right people, never to protect anything.
- Desktop only. It needs Node (
require); on a phone nobody is recognised, and nothing breaks. - The address never leaves the computer: it is read locally and compared with the notes. Our probes printed table names and note names only, never an address.
- On a Mac, a changed module is only picked up after restarting Obsidian. The new file arrived through OneDrive, but the module already loaded kept running; on Windows the change was taken at once.
- Fail closed and quietly: an unreadable account, OneDrive signed out, an address in no note or in two, all give “not recognised”, with a line in the console and no notice.
vault.getConfigis not part of the public API; it has worked for us on Obsidian 1.x.
Has anyone done the same with other sync clients (Google Drive, Dropbox, Nextcloud), or found a cleaner way to know who reads a shared vault? I would be glad to hear about it.