obsidian-advanced-uri
obsidian-advanced-uri copied to clipboard
Allow `openmode` on `commandname` or `commandid` URIs
I would like to be able to specify an openmode and run a command afterward. My use case is to create a new window and then run the create unique note command so that I get a floating window that I can move over/around the thing I'm taking notes on without affecting my main Obsidian layout.
I have a workaround for this right now because command URIs can specify filepaths. I had to look into the code to see what exactly had to be done to pass the openmode parameter to the open call -
- Create a dummy file that will always be empty
- Create a command URI
- Add a
filepathparameter pointing at the dummy file, and amode=overwriteparameter (since we need to have amodespecified in order to reach the code path that callsthis.plugin.open, also, this is why I kept the dummy file empty - it's just going to get emptied anyway) - Now add an
openmodeparameter
My final workaround looks something like this:
obsidian://advanced-uri/?vault=notes&commandid=zk-prefixer&filepath=dummy-file&mode=overwrite&openmode=window
Or spread out for readability:
obsidian://advanced-uri/
? vault=notes
& commandid=zk-prefixer
& filepath=dummy-file
& mode=overwrite
& openmode=window
Not having to have a dummy file to open a new window would be strongly preferred, but this workaround does roughly what I need it to do.
Shouldn't this else case be sufficient, so you don't need to pass a mode? So you can just any filepath. I don't think, adding an open call if you pass no filepath to be opened, is a good idea.
I finally got around to testing it, and yes, I can omit the mode and it still do what I want. However, I still need to pass a filepath to get to that branch in the code.
I don't really know how the code is structured underneath, but the reason I want to be able to open a new window without specifying a file is because the command I'm running creates a new file - and thus I don't need to open a file to run the command but I do want a new window to run the command in. It would be a little nicer in this case to not have to open an intermediate file. What about allowing creating a new window with the default Obsidian "New tab" instead? That would make use cases like this cleaner.
For completeness, my current URL is:
obsidian://advanced-uri/?vault=notes&commandid=zk-prefixer&filepath=dummy-file&openmode=window
Is now available in v1.43.0 :tada: