Run shell command when link is clicked #193
Replies: 8 comments 12 replies
-
Summary of plans(Added 2022-04-09).
My original postHi, thank you for your message! 🙂 The idea of a link or button to execute shell commands is nice, and it's been actually suggested before, but it took some time for me to find where it was suggested.
Thank you for the tip about the Buttons plugin. I tested it quickly just to see the syntax it uses to create buttons. Here's an example (as a note to myself):
If SC would add a similar feature, then I guess a block code syntax would be a good choice for SC, too. I'll update this discussion when I get better plans for how to implement this. I can see two different types of features here:
A possible quick and dirty workaroundThe only quick and dirty workaround I can figure out now is that you could add a shell command to a context menu that appears when you right click a link in the editor.
Another possible quick and dirty workaroundWell, another idea just came to my mind. This is really different than what you were looking for, but let's see.
If you have multiple note files with a different PDF file for each of them, each of the note files can have their own YAML section, containing path to that note file's related PDF. Whenever you use that shell command, you just need to have a file open that contains a YAML section that contains a |
Beta Was this translation helpful? Give feedback.
-
Hello @Taitava !!!!!!! If you don't mind, I think I have a suggestion ... let's see :) If I understood correctly, our Obsidian friend wants to execute an SC command from a link that is inside a note. To do this, you need to install an plugin called Obsidian Advanced URI
This way you can create a URI for you SC command. Following the instruction of the plugin you will see that is easy. This is the looks like URI for your SC command:
Just add this URI to text like this ....
Go to Reading view and click on the link and you SC will be executed :) I hope it helps. I'm not 100% sure if I understood your workflow but I hope it is what you want. Have a great day 🌞 |
Beta Was this translation helpful? Give feedback.
-
Hi @Taitava and @FelipeRearden! Thanks for the quick replies! Let's start with the suggestion of @FelipeRearden. I was not able make this work: When I click the link nothing happens. I created an alias
where Both the two methods suggested by @Taitava, seems to work fine here.. but here is my opinion (maybe I am missing something though) All three suggestions have the drawback of having to create a new command for each page number I reference in the PDF. I am thinking that I will have many reference to different pages in that PDF file. So this will be awkward to do. For each page I will have to create a new shell command. The first suggestion of @Taitava additionally has the drawback of having to copy the pdf file into the vault. I would like to avoid this to only keep one copy of the PDF file on the computer. I might be able to use a symbolic link in the vault though.. The second suggestion of @Taitava has the drawback of not being a clickable link but a keyboard shortcut instead. I think this will get confusing if there many references to different pages in the same file. In addition to having to define all the shell commands (one for each page reference) Summary: none of the suggestions seems very promising to me.
I am new to javascript and plugin writing but I can try to investigate this also. Wouldn't investigating the source code of the plugin obsidian-advanced-uri suggested by @FelipeRearden be a starting point? It must somehow parse the URL when we click it, right? I also found this plugin which might reveal something about hooking into the URL link parsing when user clicks a link. What do you think? |
Beta Was this translation helpful? Give feedback.
-
@FelipeRearden Yes this worked for me know. Cool! Anyway, we still have the issue with having to specify a shell command for each page number..
I think mostly the first case: every page have a different note. But some notes might have references to different pages though.. |
Beta Was this translation helpful? Give feedback.
-
Great!!!!
If I were you I would go for this strategy ... 1- Use a plugin like Apply Patterns or Advanced Cursors or another plugin that deals with regex to select the 2- SC has a variable Following your example would be something like this:
This way you could have a single SC for every page BUT you have to test the right regex query to select the page_number of the note. This is everything that I can think about this workflow. I let you know if I found any other idea. Have a great day!!!!! |
Beta Was this translation helpful? Give feedback.
-
I got two ideas of how this could work. Let's use the obsidian protocol name
where in this example I would have created an alias called Or, alternatively as the second idea: to avoid repetition of the number 77 in both the link text and in the protocol parameter, allow for defining javascript parser functions (let's say these parser functions can be defined in the shell command settings page). Then the link could look like this instead:
here What do you think? |
Beta Was this translation helpful? Give feedback.
-
One more attempt to help ... Since you know how to code code, maybe you could create an Templater script to select the page in the link while click with the mouse. Resources that I found that could corroborate my idea. There is a Templater script that uses the mouse click on a link (internal) ✉️ This is the post on Discord 📽 This is the Video: 👨💻 This is the Code: Maybe triggers something :) Have a great day! |
Beta Was this translation helpful? Give feedback.
-
To sum this all upI just wrote a quick summary of the development plans in my first message above. The first thing to go ahead with is #195. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, I am new to obsidian. Thanks for writing this nice plugin. What I would like to do is to create a note which references a pdf file. So for example, if I have a note "PDF object streams.md" :
So now instead of just having the last sentence "See page 77 in the PDF reference manual." it would be great if we could click on that as a link and it would open the PDF viewer with the correct document at page 77.
I am on Linux, so I think the following shell command should do
okular -p 77 /path/to/pdf_reference.pdf
, whereokular
is my PDF viewer of choice. Is it possible to do with this plugin?So in general: How to run a shell command when a link (or button, or something else that is clickable) is clicked? I also saw this plugin which can create buttons, but I think it cannot run external commands.
Beta Was this translation helpful? Give feedback.
All reactions