Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow openmode on commandname or commandid URIs #163

Closed
cromo opened this issue Mar 25, 2024 · 4 comments
Closed

Allow openmode on commandname or commandid URIs #163

cromo opened this issue Mar 25, 2024 · 4 comments

Comments

@cromo
Copy link

cromo commented Mar 25, 2024

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 -

  1. Create a dummy file that will always be empty
  2. Create a command URI
  3. Add a filepath parameter pointing at the dummy file, and a mode=overwrite parameter (since we need to have a mode specified in order to reach the code path that calls this.plugin.open, also, this is why I kept the dummy file empty - it's just going to get emptied anyway)
  4. Now add an openmode parameter

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.

@cromo cromo changed the title Allow openmode Allow openmode on commandname or commandid URLs Mar 25, 2024
@cromo cromo changed the title Allow openmode on commandname or commandid URLs Allow openmode on commandname or commandid URIs Mar 25, 2024
@Vinzent03
Copy link
Owner

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.

@cromo
Copy link
Author

cromo commented May 17, 2024

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

@Vinzent03
Copy link
Owner

Is now available in v1.43.0 🎉

@cromo
Copy link
Author

cromo commented Sep 14, 2024

Thank you for taking the time to understand my use case and help me work through this until the feature landed! I just checked and it works exactly as I hoped. Now my URL is:

obsidian://advanced-uri/?vault=notes&commandid=zk-prefixer&openmode=window

Much simpler!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants