Unix & Linux Stack Exchange
Q&A for users of Linux, FreeBSD and other Unix-like operating systems
Latest Questions
14
votes
2
answers
26384
views
How can I run a .desktop file?
I'm trying to write a script that launches the default application for a given mime type. For example, I would like to say `my-script text/plain` and have it open KWrite for me. What I know is that you can use xdg-mime to query what is the default application for a given mime type $ xdg-mime query d...
I'm trying to write a script that launches the default application for a given mime type. For example, I would like to say
my-script text/plain
and have it open KWrite for me.
What I know is that you can use xdg-mime to query what is the default application for a given mime type
$ xdg-mime query default text/plain
org.kde.kwrite.desktop
However, I don't know what is the command I can use to launch KWrite given org.kde.kwrite.desktop
. How can I do that? Is having the name of the desktop file enough or do I also need to find out where it is stored (/usr/share/applications
, .local/share/applications
, etc)?
-------
By the way, I don't think I can solve my original problem using xdg-open
because XDG open expects to receive a filename or URL as a parameter and I want to be able to launch my applications without needing to pass a filename. For example, I want to be able to open the text editor on a blank file buffer or open my web browser on its home page.
hugomg
(6057 rep)
Aug 25, 2016, 08:00 PM
• Last activity: Jul 17, 2025, 04:42 PM
2
votes
1
answers
4019
views
Unable to open URL with xdg-open
Getting this error as regular user: ``` ~$ xdg-open http://www.google.com/ xdg-open: no method available for opening 'http://www.google.com/' ~$ ~$ xdg-mime query default text/html ~$ ``` Code from /usr/bin/xdg-open # if BROWSER variable is not set, check some well known browsers instead if [ x"$BRO...
Getting this error as regular user:
~$ xdg-open http://www.google.com/
xdg-open: no method available for opening 'http://www.google.com/ '
~$
~$ xdg-mime query default text/html
~$
Code from /usr/bin/xdg-open
# if BROWSER variable is not set, check some well known browsers instead
if [ x"$BROWSER" = x"chromium" ]; then
BROWSER=links2:elinks:links:lynx:w3m
if [ -n "$DISPLAY" ]; then
BROWSER=firefox:mozilla:epiphany:konqueror:chromium:google-chrome:$BROW$
fi
fi
open_envvar "$1"
exit_failure_operation_impossible "no method available for opening '$1'"
}
----
Operating system: Ubuntu 16.04 Gnu/Linux
xavier96
(21 rep)
Apr 11, 2020, 01:39 PM
• Last activity: Jul 14, 2025, 08:06 PM
0
votes
1
answers
2735
views
Launching a program via `xdg-open` from a subshell without blocking
I've noticed that calling `xdg-open` from a subshell will reliably block until the launched process is closed. I suspect there may be a reason for this, but I'm not sure as to why. For example, launching Nautilus doesn't block when calling `xdg-open` directly from the command line: xdg-open ~/dir ;...
I've noticed that calling
xdg-open
from a subshell will reliably block until the launched process is closed. I suspect there may be a reason for this, but I'm not sure as to why. For example, launching Nautilus doesn't block when calling xdg-open
directly from the command line:
xdg-open ~/dir ; echo foo # doesn't block
but invoking xdg-open from a subshell will reliably block the terminal
var=$(xdg-open ~/dir ; echo foo) # blocks
{ xdg-open ~/dir ; echo foo ; } | cat # blocks.
My understanding is that xdg-open
detaches the launched process from the shell session so that it's no longer a subprocess. I'd therefore expect this to be different to e.g. invoking sleep 1 &
in a subshell for which it seems reasonable that the terminating subshell will block until all subprocess have completed, i.e.
var=$(sleep 1 & echo foo) # also blocks, but understandable.
But if xdg-open
is detaching the process, what's causing the subshell to wait?
In what may (?) be a partial answer, I've noticed that running
{ xdg-open ; ps ; } | cat
shows that depending on program launched by ``, those that block are also the ones that keep the tty as their controlling terminal. That begs the question why this happens, why this happens only in a subshell and ultimately what's a good way to a launch desktop process from the terminal that will fully and reliably detach from it?
Edit: fix syntax on bash
.
wardw
(396 rep)
Dec 12, 2020, 08:08 PM
• Last activity: May 14, 2025, 12:06 AM
1
votes
1
answers
2326
views
chromium: specify file association, instead of opening file in xdg-open
When I click on a file in `chromium`, it calls `xdg-open` to open the file based on its mime type. For example, if I click on a file with a `.torrent` extension, it opens it in my torrent client. Is it possible to disable the use of `xdg-open`, and instead specify which extensions should be opened i...
When I click on a file in
chromium
, it calls xdg-open
to open the file based on its mime type.
For example, if I click on a file with a .torrent
extension, it opens it in my torrent client.
Is it possible to disable the use of xdg-open
, and instead specify which extensions should be opened in which applications?
Martin Vegter
(586 rep)
Sep 6, 2020, 03:51 PM
• Last activity: May 13, 2025, 09:02 PM
1
votes
1
answers
61
views
Query which desktop files can handle a mime type: Open with from the terminal?
So if I add a desktop to entry `~/.local/share/applications/something.desktop` then it shows up in the "Open with..." menu in KDE straight away. I would quite like to be able to get this same information from the command line. Is there a way of querying this? I had a look an `xdg-mime` which can sho...
So if I add a desktop to entry
~/.local/share/applications/something.desktop
then it shows up in the "Open with..." menu in KDE straight away. I would quite like to be able to get this same information from the command line.
Is there a way of querying this? I had a look an xdg-mime
which can show the default application, and set the default application to this newly created desktop entry but seems unable to list them all. Obviously I could just code up something to parse all the desktop entries - but this seems besides the point.
There is this stuff about mimeinfo.cache
and mimeapp.list
but this seems parallel to these files - since open with... lists shows the new desktop entry, but it is missing from both these files.
How do I show all desktop files that can handle a mimetype from the command-line?
Att Righ
(1412 rep)
Apr 4, 2025, 06:27 PM
• Last activity: Apr 5, 2025, 12:28 PM
57
votes
3
answers
64704
views
How does the xdg-open command know which application to use to open a file?
I would expect xdg-open command to use the same application that opens when I double-click the file in the default file manager, but this is not always true. For example my DE is XFCE, my file manager is Thunar and my default picture viewer is Ristretto. However, `xdg-open example.png` opens the exa...
I would expect xdg-open command to use the same application that opens when I double-click the file in the default file manager, but this is not always true.
For example my DE is XFCE, my file manager is Thunar and my default picture viewer is Ristretto. However,
xdg-open example.png
opens the example PNG file in Pinta. Why?
Ivan
(18358 rep)
Dec 23, 2015, 02:44 AM
• Last activity: Nov 26, 2024, 10:20 PM
2
votes
2
answers
2313
views
Syntax check ~/.config/mimeapps.list
Is there a way of checking for syntax errors in `~/.config/mimeapps.list`? Errors seem to be silently ignored: 1. I added `fdsobojaba` to the bottom of the file 2. I ran xdg-open on an existing file 3. There was no error in `.xsession-errors` How do I verify `mimeapps.list`? Or at worst, where is th...
Is there a way of checking for syntax errors in
~/.config/mimeapps.list
?
Errors seem to be silently ignored:
1. I added fdsobojaba
to the bottom of the file
2. I ran xdg-open on an existing file
3. There was no error in .xsession-errors
How do I verify mimeapps.list
? Or at worst, where is the definition of the file's format?
Tom Hale
(32892 rep)
Jun 23, 2017, 10:45 AM
• Last activity: Nov 26, 2024, 08:27 PM
13
votes
2
answers
65037
views
xdg-open is installed yet also is not installed
$ xdg-open The program 'xdg-open' is currently not installed. You can install it by typing: sudo apt-get install xdg-utils $ sudo apt-get install xdg-utils Reading package lists... Done Building dependency tree Reading state information... Done xdg-utils is already the newest version. 0 upgraded, 0...
$ xdg-open
The program 'xdg-open' is currently not installed. You can install it by typing:
sudo apt-get install xdg-utils
$ sudo apt-get install xdg-utils
Reading package lists... Done
Building dependency tree
Reading state information... Done
xdg-utils is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 89 not upgraded.
$ whereis xdg-open
xdg-open: /usr/bin/xdg-open /usr/bin/X11/xdg-open /usr/share/man/man1/xdg-open.1.gz
$ which xdg-open
$ xdg-open
The program 'xdg-open' is currently not installed. You can install it by typing:
sudo apt-get install xdg-utils
No, I didn't mean "recursion".
I'm on Linux Mint 15 MATE, but instead of MATE I'm using the i3 window manager.
**Edit taking @slm's advice**
$ type -a xdg-open
type: xdg-open not found
But it's in /usr/bin/xdg-open. I checked.
$ dpkg -S /usr/bin/xdg-open
xdg-utils: /usr/bin/xdg-open
The next one was even more interesting.
$ dpkg -S xdg-open
git-annex: /usr/share/doc/git-annex/html/bugs/Fix_for_opening_a_browser_on_a_mac___40__or_xdg-open_on_linux__47__bsd__63____41__.html
xdg-utils: /usr/bin/xdg-open
xdg-utils: /usr/share/man/man1/xdg-open.1.gz
The bug-fix is just a mail archive of a patch for an OSX problem. Anyway, I guess I could try using the full path:
$ /usr/bin/xdg-open
/usr/bin/xdg-open: No such file or directory
nacnudus
(273 rep)
Nov 16, 2013, 03:49 AM
• Last activity: Nov 25, 2024, 10:19 AM
3
votes
2
answers
1989
views
Escape spaces in path in export variable (Ubuntu 22.04.1 LTS)
I use WSL2 (Ubuntu 22.04.1 LTS) and need to refer to edge-browser for xdg-open. Due to the space in the path I get an error. How can I escape the space? The path is shown corrrectly in exported variable BROWSER. oliverk@KPW00WP3Q:/mnt/c/Users/E547766/Documents$ export BROWSER="/mnt/c/Program Files (...
I use WSL2 (Ubuntu 22.04.1 LTS) and need to refer to edge-browser for xdg-open. Due to the space in the path I get an error. How can I escape the space? The path is shown corrrectly in exported variable BROWSER.
oliverk@KPW00WP3Q:/mnt/c/Users/E547766/Documents$ export BROWSER="/mnt/c/Program Files (x86)/Microsoft/Edge/Application/msedge.exe"
oliverk@KPW00WP3Q:/mnt/c/Users/E547766/Documents$ xdg-open https://stackoverflow.com/questions/24683221
/usr/bin/xdg-open: 882: /mnt/c/Program: not found
/usr/bin/xdg-open: 882: /mnt/c/Program: not found
xdg-open: no method available for opening 'https://stackoverflow.com/questions/24683221 '
oliverk@KPW00WP3Q:/mnt/c/Users/E547766/Documents$ export BROWSER='/mnt/c/Program Files (x86)/Microsoft/Edge/Application/msedge.exe'
oliverk@KPW00WP3Q:/mnt/c/Users/E547766/Documents$ xdg-open https://stackoverflow.com/questions/24683221
/usr/bin/xdg-open: 882: /mnt/c/Program: not found
/usr/bin/xdg-open: 882: /mnt/c/Program: not found
xdg-open: no method available for opening 'https://stackoverflow.com/questions/24683221 '
oliverk@KPW00WP3Q:/mnt/c/Users/E547766/Documents$ $BROWSER
-bash: /mnt/c/Program: No such file or directory
oliverk@KPW00WP3Q:/mnt/c/Users/E547766/Documents$ export
declare -x BROWSER="/mnt/c/Program Files (x86)/Microsoft/Edge/Application/msedge.exe"
Daniel
(53 rep)
Aug 29, 2022, 07:08 PM
• Last activity: Oct 11, 2024, 01:55 PM
0
votes
0
answers
88
views
xdg-open & callto link & google chrome
I have a strange situation. In my company we use Xivo for all our call, so we have xivo-desktop-assistant installed on our desktop. Everything works fine with Firefox, when we click callto or tel link, xivo-desktop is open and compose, but we study to move on chrome alternative. Every time I want to...
I have a strange situation. In my company we use Xivo for all our call, so we have xivo-desktop-assistant installed on our desktop. Everything works fine with Firefox, when we click callto or tel link, xivo-desktop is open and compose, but we study to move on chrome alternative.
Every time I want to open a callto or tel link from Google Chrome or other browser based on Chrome, xdg open firefox but not Xivo-desktop.
I try in command line to do
xdg-open callto:123
(to call 123) he still open Firefox (if I remove firefox from desktop, xdg try to open other apps but no Xivo-desktop).
So it's look to be a xdg problem.
If I do something like xdg-settings get default-url-scheme-handler callto
(same with tel)
the answer is xivo-desktop-assistant.desktop
who looks good.
But I don't understand why xdg don't want to work correctly.
All file I check in ~/.local/share/applications, /usr/share/mime, /usr/share/applications looks to be good.
During I make tests for this post, I see if the phone number is 6 or more digit it's working... where I can make this change ? (or internal number are on 3 digit).
OS: Ubuntu 24.04 with KDE
Any idea ?
---
More information, if I do something like : /opt/xivo-desktop-assistant/xivo-desktop-assistant callto:123
it's working
Thanks for you help
Totorux
(1 rep)
Sep 12, 2024, 08:31 AM
• Last activity: Sep 12, 2024, 12:45 PM
5
votes
1
answers
729
views
Open a url with a custom protocol from the command line
`xdg-open` can open urls, but only ones starting with `ftp`, `http` or `https`. But my browser will happily open other urls in programs that have a handler for it registered, e.g. `f5-vpn://` urls (for a vpn, this launches the vpn client after authenticating in a web app). How can I open other urls...
xdg-open
can open urls, but only ones starting with ftp
, http
or https
. But my browser will happily open other urls in programs that have a handler for it registered, e.g. f5-vpn://
urls (for a vpn, this launches the vpn client after authenticating in a web app).
How can I open other urls like f5-vpn://
with their registered handler from the command line, just like the browser does?
JanKanis
(1421 rep)
Aug 13, 2024, 02:44 PM
• Last activity: Aug 14, 2024, 07:09 AM
13
votes
2
answers
4380
views
xdg-open opens a different application to the one specified by xdg-mime query
I run Debian Jessie without a desktop environment (I use the tiling window manager i3) and like to use `xdg-open` to quickly open files using a preferred application. I have an ongoing problem setting the preferred app for PDF files though. This is my problem in a nutshell: $ xdg-mime query filetype...
I run Debian Jessie without a desktop environment (I use the tiling window manager i3) and like to use
xdg-open
to quickly open files using a preferred application. I have an ongoing problem setting the preferred app for PDF files though. This is my problem in a nutshell:
$ xdg-mime query filetype ~/Downloads/document.pdf
application/pdf
$ xdg-mime query default application/pdf
/usr/share/applications/qpdfview.desktop
$ xdg-open ~/Downloads/document.pdf
[opens gimp!]
Any ideas would be hugely appreciated - this has been plaguing me for about a year. The only way I've ever managed to (temporarily) fix it is by directly editing the mimeinfo.cache
and removing the reference to gimp
from the application/pdf
record.
And yes, /usr/share/applications/qpdfview.desktop
exists and contains the correct location of the qpdfview
binary. (Indeed, this .desktop file is used when I hand-edit mimeinfo.cache
.)
Tim
(233 rep)
Jun 3, 2014, 10:46 PM
• Last activity: Aug 5, 2024, 09:55 AM
1
votes
1
answers
310
views
Can I force xdg-open to use a new terminal when opening a terminal app?
I would like `xdg-open` to open a new terminal when I run it on a file from the terminal and it opens, for example, nvim. My default text editor for `text/plain` is set to `nvim.desktop`. When I open a `text/plain` file from dolphin, it correctly opens nvim in a new terminal. But when I run `xdg-ope...
I would like
xdg-open
to open a new terminal when I run it on a file from the terminal and it opens, for example, nvim.
My default text editor for text/plain
is set to nvim.desktop
. When I open a text/plain
file from dolphin, it correctly opens nvim in a new terminal. But when I run xdg-open
on that same file from a terminal, it opens nvim in the current terminal instead of starting a new one. How can I force xdg-open
to open programs with a Terminal=true
flag in their .desktop file in a new terminal when I run xdg-open from a terminal?
I already tried { cat | xdg-open ~/file.txt 2>&1 >>/dev/null ; } & disown
(file.txt is present in the home directory) but nothing happens, nvim
is not even running if I type pgrep nvim
after...
My terminal is konsole, I am using Hyprland as window manager.
Edit:
I found out gio open
does this correctly, so for now I will just use that. (I'll consider making it the answer, but I'll just wait a couple of days to see if I get an answer for xdg-open.)
vosjedev
(11 rep)
Jun 4, 2024, 06:45 AM
• Last activity: Jun 4, 2024, 07:19 AM
0
votes
1
answers
797
views
Open specific URLs in certain app?
How can I tell `xdg-open` to open, say, YouTube URLs in a specific app, but use my default browser for all other URLs?
How can I tell
xdg-open
to open, say, YouTube URLs in a specific app, but use my default browser for all other URLs?
Geremia
(1252 rep)
May 28, 2024, 12:02 AM
• Last activity: May 28, 2024, 01:18 AM
17
votes
3
answers
147432
views
How to open an .png type image in Linux terminal?
I just can't find the command to display a *.png image! I tried `xdg-open` command but it failed: [student@seqpapl1 Images]$ xdg-open adapter_content.png xdg-open: no method available for opening 'adapter_content.png' I am currently running ubuntu linux on the server.
I just can't find the command to display a *.png image! I tried
xdg-open
command but it failed:
[student@seqpapl1 Images]$ xdg-open adapter_content.png
xdg-open: no method available for opening 'adapter_content.png'
I am currently running ubuntu linux on the server.
Genie
(173 rep)
Jan 2, 2019, 07:50 PM
• Last activity: Apr 24, 2024, 02:36 PM
0
votes
1
answers
205
views
Is it Possible to Read stdout and stderr of Apps Launched From the Desktop?
Suppose I launch Firefox from my apps. Is the stdout and stderr redirected to a specific file or is it redirected to `/dev/null`? If it is indeed redirected to a specific file, I'd also like to know how to how to run applications from the terminal (e.g. nohup, & disown) without knowing where to redi...
Suppose I launch Firefox from my apps. Is the stdout and stderr redirected to a specific file or is it redirected to
/dev/null
? If it is indeed redirected to a specific file, I'd also like to know how to how to run applications from the terminal (e.g. nohup, & disown) without knowing where to redirect stdout and stdin. In other words, how would I tell the desktop to launch an app, instead of launching it from terminal myself as a detached process. Of course, if the redirection is to /dev/null
, then nohup APP >/dev/null 2>&1
and & disown
is sufficient.
Elijah
(123 rep)
Feb 24, 2024, 08:15 PM
• Last activity: Feb 25, 2024, 02:52 AM
18
votes
2
answers
59300
views
What's the right way to add directories to XDG_DATA_DIRS?
I've installed some app under `/opt/myapp`, which has a `/opt/myapp/share` directory. As I finish installing, it tells me: Note that '/opt/myapp/share' is not in the search path set by the XDG_DATA_HOME and XDG_DATA_DIRS environment variables, so applications may not be able to find it until you set...
I've installed some app under
/opt/myapp
, which has a /opt/myapp/share
directory. As I finish installing, it tells me:
Note that '/opt/myapp/share' is not in the search path
set by the XDG_DATA_HOME and XDG_DATA_DIRS
environment variables, so applications may not
be able to find it until you set them. The
directories currently searched are:
- /usr/share/gnome
- /home/joeuser/.local/share/flatpak/exports/share
- /var/lib/flatpak/exports/share
- /usr/local/share
- /usr/share
What's the right way to add directories to that list - system-wide and as a single user?
einpoklum
(10753 rep)
Sep 25, 2018, 01:24 PM
• Last activity: Feb 17, 2024, 02:09 PM
51
votes
2
answers
43075
views
Create a custom URL Protocol Handler
I would like to register a URL scheme (or protocol) handler for my own custom URL protocol, so that clicking on a link with this custom protocol will execute a command on that URL. Which steps do I need to take to add this handler? Example: I want to open URLs like `ddg://query%20terms` in a new Duc...
I would like to register a URL scheme (or protocol) handler for my own custom URL protocol, so that clicking on a link with this custom protocol will execute a command on that URL. Which steps do I need to take to add this handler?
Example: I want to open URLs like
ddg://query%20terms
in a new DuckDuckGo browser search. If this protocol already exists, I assume that the steps to override a handler don't differ much from the steps to create a new one. Yes, technically, this is just a URL scheme, not a protocol.
palswim
(5597 rep)
Jan 28, 2019, 07:31 AM
• Last activity: Jan 23, 2024, 03:34 PM
0
votes
2
answers
112
views
How to open a file starting with dash via xdg-open
Usually, a double dash separates options from filenames, but xdg-open does not care: ```sh ❯ xdg-open -headlinesAfter.epub xdg-open: unexpected option '-headlinesAfter.epub' Try 'xdg-open --help' for more information. ❯ xdg-open -- -headlinesAfter.epub xdg-open: unexpected option '--' Try 'xdg-open...
Usually, a double dash separates options from filenames, but xdg-open does not care:
❯ xdg-open -headlinesAfter.epub
xdg-open: unexpected option '-headlinesAfter.epub'
Try 'xdg-open --help' for more information.
❯ xdg-open -- -headlinesAfter.epub
xdg-open: unexpected option '--'
Try 'xdg-open --help' for more information.
Is there any other way?
xeruf
(631 rep)
Sep 3, 2023, 08:59 PM
• Last activity: Sep 4, 2023, 09:08 AM
1
votes
0
answers
169
views
Design .desktop File to Launch the Default Terminal Emulator with Arguments
I'd like to be able to open text and source code files in neovim (or any other terminal-based text editor) when an XDG-compatible GUI application asks with which application to open that file. For now, I'd be targetting xfce and cinnamon as DE/session provider. For that, I'd write a neovim-in-defaul...
I'd like to be able to open text and source code files in neovim (or any other terminal-based text editor) when an XDG-compatible GUI application asks with which application to open that file. For now, I'd be targetting xfce and cinnamon as DE/session provider.
For that, I'd write a neovim-in-default-terminal-emulator.desktop file, and start the configured default terminal emulator with the appropriate editor command.
What do I need to do to launch the DE-configured default terminal emulator from a application .desktop file with arguments of my choosing?
- It doesn't seem
update-alternatives
on modern non-debian systems (fedora38, and others) provides x-terminal-emulator
(anymore?)
- gsettings
-based aproaches: not my go-to, since DE-dependent, which technically is a no-go for a .desktop file which is supposed to be DE-agnostic
- I was first hoping for default-url-scheme-handler
and then DEs registering their preferred terminal emulator for some console://
or similar URL, but xdg-settings get default-url-scheme-handler
is all xdg-settings: default-url-scheme-handler not implemented for xfce
on me (does that mean I can't open, say, skype:// URLs from a browser when operating under XFCE?!)
- :-(
Marcus Müller
(47107 rep)
Sep 3, 2023, 04:47 PM
Showing page 1 of 20 total questions