View previous topic :: View next topic |
Author |
Message |
pablo_supertux Advocate
Joined: 25 Jan 2004 Posts: 2942 Location: Somewhere between reality and Middle-Earth and in Freiburg (Germany)
|
Posted: Fri May 24, 2024 8:56 pm Post subject: xdg-open with custom handler does not work [solved] |
|
|
Hi
I want the xdg-open opens http and https links either on google-chrome or firefox depending on certain conditions. So I created my own bash script that checks for these conditions and select the correct browser.
Then I created a .desktop file that would call this script of mine. The file is called /home/shaoran/.local/share/applications/url-open.desktop and looks like this:
Code: |
Desktop Entry]
Version=1.0
Name=url-open
GenericName=Web Browser
Type=Application
Exec=/home/shaoran/local/bin/url-open %f
MimeType=x-scheme-handler/http;x-scheme-handler/https;
|
Then I set the default entry like this:
Code: |
xdg-mime default url-open.desktop x-scheme-handler/http
xdg-mime default url-open.desktop x-scheme-handler/https
|
I also noticed that tab-completion with xdg-mime default <TAB><TAB> would show me lots of .desktop files but url-open.desktop is not in the list. Do I need to do something else to register a .desktop file other than put it in ~/.local/share/applications?
I checked my ~/.config/mimeapps.list and I can see
Code: |
...
[Default Applications]
...
x-scheme-handler/http=url-open.desktop
x-scheme-handler/https=url-open.desktop
|
and xdg-mime query default x-scheme-handler/http also returns url-open.desktop.
But when I test it, it still not using my script but opens a new tab in firefox and I get this error message:
Code: |
$ xdg-open http://google.com
/usr/bin/xdg-open: line 1032: x-www-browser: command not found
|
I searched for this error message and found this https://bugzilla.redhat.com/show_bug.cgi?id=755553#c9
That would explain why I'm getting this error message. However, if I do
Code: |
xdg-mime default url-open.desktop x-scheme-handler/http
xdg-mime default url-open.desktop x-scheme-handler/https
|
and then run xdg-open http://google.com, then the link is opened in google-chrome and the x-www-browser: command not found messages does not appear.
Why is this the case? What am I doing wrong? _________________ A! Elbereth Gilthoniel!
silivren penna míriel
o menel aglar elenath,
Gilthoniel, A! Elbereth!
Last edited by pablo_supertux on Fri May 24, 2024 10:23 pm; edited 1 time in total |
|
Back to top |
|
|
pablo_supertux Advocate
Joined: 25 Jan 2004 Posts: 2942 Location: Somewhere between reality and Middle-Earth and in Freiburg (Germany)
|
Posted: Fri May 24, 2024 10:23 pm Post subject: |
|
|
I know now what the error is: in the .desktop file the Exec line should be this
Code: |
Exec=/home/shaoran/local/bin/url-open %U
|
Using %U instead of %f does the trick.
Debugging shell scripts can be such a pain and I realized that xdg-open simply skips the .desktop file if the argument is %f. So I looked up the specs and found this: https://specifications.freedesktop.org/desktop-entry-spec/latest/ar01s07.html There it says I should use %u for a single url and %U for multiple urls. I checked in the google-chrome.desktop file and there %U is being used as well. _________________ A! Elbereth Gilthoniel!
silivren penna míriel
o menel aglar elenath,
Gilthoniel, A! Elbereth! |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|