Open to Offset plugin

I had a need to open a file to a specific offset (absolute position) via an external command. Mainly for an Alfred workflow I’m working on that leverages the Omnisearch API. I scratched my own itch and wrote this simple plugin:

Right now there are no settings, all it does is register the protocol handler obsidian://open-to-offset.

Would love any tips or critiques from the community before I attempt to submit this officially to the community plugin registry.

Is there a better or more correct method than this.app.workspace.openLinkText() to open a note to a specific location?

I think what you are looking for has been done in the omnisearch plugin here: obsidian-omnisearch/src/tools/notes.ts at c34503f1cd89a5e6bd1813cc608b698ced890189 · scambier/obsidian-omnisearch · GitHub

I have opened a feature request in advanced-uri to add it Open file to specific offset · Issue #181 · Vinzent03/obsidian-advanced-uri · GitHub

Also, I have been using your plugin and it works great. Do you think it would be possible to add an option to pass in a word and select that word from the offset? So if I pass in offset 10 and word “foo” then it would start at offset 10 look for the first instance of the word “foo” and highlight it.

That should be possible but I have been watching the Advanced URI repo and I saw that Vinzent added an open to offset function URI to his plugin (not published yet). I will see if I can make the feature you’re asking for but my goal for the plugin was just a temporary stopgap until Adv. URI supported it natively.

I see he has added the ability to go to a col number in feat: set cursor to column in line · Vinzent03/obsidian-advanced-uri@414277d · GitHub, but ideally we would be able to go to an offset, as we only get the offset back from omnisearch, though I suppose with some introspection on the file you could get the line/col from that.

I’ll keep watching the repo too.

Advanced URI 1.42 was just released, supporting the new column parameter. But, I tested it and it’s relative to the line only. So for example in a 500-character note, passing ?column=410 won’t work.

I’ll work on seeing if I can enhance my plugin to support the feature you asked for @wayneh. Need to find some time.

Just updating this, Advanced URI does support an offset= param now which works well. I am still hoping a rainy day comes when I can add the “open from offset with selectioin” command.

obsidian://adv-uri?filepath=Foo&offset=1234