URL Encoding Issue with Variables

I'm using Obsidian and want to build an Obsidian URL for a note. The vault and folder are fixed.

The idea is to concatenate this text: obsidian://open?vault=VaultName&file=%3DPeople%2F
with my encoded name: "John%20Smith", in the variable LocalEncodedName

I'm doing this with the Set Variable action, like so:
obsidian://open?vault=VaultName&file=%3DPeople%2F%Variable%LocalEncodedName%

Desired: obsidian://open?vault=VaultName&file=%3DPeople%2FJohn%20Smith
Actual: obsidian://open?vault=VaultName&file=%3DPeople/VariableJohn%20Smith

It's like I need to escape the variable somehow while setting it. And yes, my People folder is actually =People, so when I'm searching for a person, it's CMD+O then = and it filters all the notes to just those in the =People folder.

Any ideas?

% is a special character in a KM text field, indicating a token when a token can be created from what follows. But KM is smart enough to treat it as just a % character when there's no token present.

That's why the %3DPeople part of your string comes through unscathed. But %2F% is a text token -- see "Convert Hex to Unicode Characters" in the manual's "Other Uses for Tokens" section -- and you can see the / it represents in your string. In the process, that gobbles up the leading % on your variable token, breaking it.

Play safe -- encode your "should be text" %s by preceding them with an extra %:

obsidian://open?vault=VaultName&file=%%3DPeople%%2F%Variable%LocalEncodedName%

Thanks! I appreciate the explanation as much as the solution.

1 Like