Xdg-open Fix

This is for any frustrated by Google Chrome using random applications to open its downloads.
Google Chrome uses xdg-open to open its downloads. Since I don't use Gnome or KDE, the DE environment variable is unset. If the DE environment variable is unset or set to "generic", xdg-open uses the open_generic_xdg_mime() function to choose the application to open files. This function incorrectly determines the location of the .desktop file. It will come up with something like
/usr/share/applications//usr/share/applications/mplayer.desktop
instead of
/usr/share/applications/mplayer.desktop.
To fix this I added
default=`echo $default | sed "s|[^\w]*/||"`
below the line (line number 384)
default=`xdg-mime query default "$filetype"`.
Setting the default application with xdg-mime default [.desktop file] [mime-type] populates the $HOME/.local/share/applications/defaults.list file. With the fix, xdg-open now correctly uses this file and open applications as expected.

By the way OP. If you are using pcmanfm: here is handy replacement for /usr/bin/xdg-open  - http://dumpz.org/15027/
It handles http(s), mail and magnet links, and on all other lets pcmanfm deside

Similar Messages

  • Fixing xdg-open

    Hi all fellow archers!
    For quite some time, those of us running without a desktop environment have been struggling to cope with xdg-open for handling file opens (especially for Chromium).
    Although xdg-open has gotten a bit better over time (it now falls back to mimeopen if it doesn't know what to do).
    Unfortunately, this solution is not a "proper" one since mimeopen currently does not work with URIs, only with files.
    To get around this, I have made two minor adjustments to my system to make it handle even URIs gracefully.
    The first is a hack, the second a (small) patch to xdg-open:
    The hack:
    ln -s /usr/share/applications/mimeinfo.cache to /usr/share/applications/defaults.list
    this will make all applications that register MIME types using MimeType= in their .desktop files the default for their respective MIMEs.
    This is required since xdg-mime does not check mimeinfo.cache when looking up applications for mime types, only defaults.list files.
    If multiple applications happen to register for the same MIME type, I'm not sure which is chosen as the default, but this should be overridden in ~/.local/share/applications/defaults.list anyway.
    The second part, the patch, can be viewed here: http://pastebin.com/EduF8GjC
    For those not used to merging patches like this, download the raw .patch file from here: http://pastebin.com/download.php?i=EduF8GjC , and then run
    sudo patch /usr/bin/xdg-open <xdg-open_uri_patch.txt
    Note that you shouldn't normally just do what strangers like me tell you to, so have a look through the .patch file before patching /usr/bin/xdg-open to make sure I haven't done something naughty.
    There are also unreleased patches for this upstream here and here if you'd prefer using those, but they may not patch nicely against the current Arch version.
    Essentially, whenever a URI is being opened with the internal, generic opener, xdg-mime is queried for the default application for "x-scheme-handler/$scheme" where $scheme is the scheme part of the URI.
    That application is then started with the full URI the path to open.
    Now sit back and enjoy Chromium opening all your files correctly, even magnet:, mailto: and spotify: links (if you've got a client for each installed of course).
    Jon
    PS: The patch has also been submitted to the Portland/XdgUtils team as bug #44873
    EDIT: Turns out this has already been patched after a similar bugreport, just not released, in these commits. The patch is still needed until a release with these changes comes though. Feel free to use the upstream patches instead if you want.
    Last edited by Jonhoo (2012-01-17 22:49:21)

    I tried to find out what was going on using strace. Here is the output:
    strace -f /usr/bin/gvfs-open file.pdf 2>&1 | grep exec
    execve("/usr/lib/xfce4/exo-1/exo-helper-1",
    Why is gvfs-open resorting to xfce's opener while I am running gnome???
    A bit earlier in the trace, gvfs loads /usr/lib/gio/modules/libexo-module-1.so which is certainly the culprit.
    My question is then: how do I make gvfs-open use gnome's facilites?
    --- edit ---
    Looks like my problem:
    https://qa.mandriva.com/show_bug.cgi?id=62203
    --- edit 2 ---
    Some more info:
    http://penguincopter.blogspot.com/2010/ … ty-of.html
    Last edited by benob (2011-02-21 18:38:56)

  • Whippet (formerly Ease): application launcher and xdg-open replacement

    Whippet is a Bash script which opens files and urls with applications associated by name and/or MIME-type. Applications and associations may be customized within an SQLite database, and can be weighted according to the importance you assign to them. Whippet can serve as an xdg-open replacement for those who wish to have total control over which applications are associated with which types of files. For more experienced users only, but ideal for integrating with light desktop environments and file managers. Whippet uses dmenu to manage its menus, and you will also need a program such as DB Browser for SQLite for managing the SQLite database. Once installed from the AUR package, execute the command 'man whippet' for more information.
    Edit on 2015-06-23: Updated for Whippet 2.1.2.
    Edit on 2015-03-15: Rebranded as Whippet; was formerly Ease.
    Last edited by ninian (Today 14:24:22)

    Version 1.2.0 has been released, with the following new features:
    Can now optionally associate applications by matching regexes to file/URI names in the configuration file.
    New option -n and configuration variable $assocname control the usage of associations by file/URI name.
    Also:
    Fixed a bug causing a loop in the fallback menu when an alternative configuration directory is specified.

  • Xdg-open and apvlv

    I recently switched to apvlv as my default pdf viewer. When I try to set it as my default pdf program in xdg-open (for chromium), with the command:
    xdg-mime default apvlv.desktop application/pdf
    xdg-open does it's favorite default behavior, which is to try to open the file in firefox. Any idea how I can fix this?

    Have you tried to create a ~/.local/share/applications/defaults.list which contains the following?
    [Default Applications]
    application/pdf=apvlv.desktop
    This works without any problems on my system. If still no luck, try to install perl-file-mimeinfo.
    Regards

  • Xdg-open doesn't open nautilus repeatedly

    HI All,
    Whenever I run "xdg-open ." from a shell, nothing happens. However, if I run it again shortly afterwards Nautilus opens up with the current directory.
    It seems that xdg-open only works if an existing Nautilus process is running. Could you guys please confirm this as well?
    Thanks,
    Saad

    This was introduced long ago when GNOME 3.14 appeared. Here is one thread about it at https://bbs.archlinux.org/viewtopic.php?id=190252.
    Only recently, somebody got around to raising a bug, see https://bugs.archlinux.org/task/45167.
    I have just lived with it assuming it was an upstream GNOME bug which would eventually get fixed.
    Last edited by bulletmark (2015-06-05 03:31:32)

  • [SOLVED] xdg-open: no method available for opening

    I'm using Openbox. Whenever I try to use xdg-open to open a file or link from the command line, I get the error "xdg-open: no method available for opening". This happens with all files and links, regardless of type. I've tried editing ~/.local/share/applications/mimeapps.list, both manually and with xdg-mime; neither had any effect. I've also tried setting environment variables such as $BROWSER; that had no effect, either.
    Strangely, exo-open works with no problem (although the only way I've found to change file associations is by using Thunar). I would just switch to exo-open, except I've encountered a couple of programs that rely on xdg-open for opening web links and the like.
    Has anyone else seen this problem? At this point, I'm pretty confused, and I would appreciate any help. Thanks!
    Last edited by morganmay (2013-11-19 16:31:08)

    Was poking around with this again. I still haven't solved the problem, but I did notice an error that might be a clue. When I enter "xdg-settings get default-url-scheme-handler", I get the error "xdg-settings: unknown desktop environment". I don't have a DE installed, just openbox (although as far as I can tell, XDG doesn't require a DE).
    Does anyone know what this means? Searches for this error have only led me to threads recommending solutions that I've already tried without success (editing mimeapps.list, setting environment variables like BROWSER, etc.).

  • Xdg-open is opening files with no extension in wine notepad

    xdg-open is opening files with no extension in wine notepad. This is really annoying. How can I change it?

    Click on "Browse" button at the "Open With" dialog and navigate to the location, where acrord32.exe is located. Preferebly, it should be this location "C:\Program Files\Adobe\Reader 9.0\Reader\AcroRd32.exe" unless you have installed at some customized location.  I'm assuming you have installed Reader 9. Once you add Adobe Reader in the open with list, it would continue to appear next time onwards.

  • [solved] xdg-open url.jpg opens it in firefox

    Hello,
    I'm working on xfce. While clicking in psi IM to a http://....image.jpg link, the image gets opened in a new card of Firefox. Firefox is my default browser. In terminal
    xdg-open http://upload.koci.net.pl/uploads/crusader.jpg
    does the same. I wish this image to be opened in my image viewer, not in Firefox. In xfce's MIME type configuration I can see image image/jpeg is set to Ristretto.
    Last edited by mkkot (2013-06-11 15:29:41)

    Creating your own script could work.  But my best recommendation would be to use one of the ready made replacements for xdg-open.  I've never used it enough to have a real opinion on it, but you're not the first to be unsatisfied with xdg-open - and when archers are unsatisfied, they write solutions.
    There is a relatively recently active thread one one archers solution to this problem ... was it mimi or mimi-open, something like that.  I've never had a need for such a tool, but it seems to have been warmly received by other users, so it may do what you want.

  • Xdg-open for irc links in chromium

    Hey!
    I know that the first thing to do is search before bothering other people and I did it a lot. Google, posts, how-to`s, wikis... I see my last chance in asking this community
    So here is my problem:
    I use chromium as default browser and konversation for irc on lxde desktop. chromium uses xdg-open to associate files and links with programs. I tried everything I found but couldn`t get it to work. When I click on an IRC link, it asks me for opening the associated program, I confirm with yes and nothing happens. When trying to open an irc link from the terminal I get
    xdg-open: no method available for opening 'irc://...'
    I got it to work with mimeo, so please no suggestions in this direction, I would like to learn how to do it without it and so to learn it distribution independently.
    For anyone looking for it, this is the working mimeo solution
    $ yaourt -Sy mimeo xdg-utils-mimeo mime-type
    $ nano /home/tom/.config/mimeo.conf
    /usr/bin/konversation
      ^irc://
    # there have to be exactly two spaces in front of ^irc://
    This is the working solution in gnome using gconf:
    $ gconftool-2 --set --type=string /desktop/gnome/url-handlers/irc/command 'konversation "%s"
    $ gconftool-2 --set --type=bool /desktop/gnome/url-handlers/irc/enabled true
    $ gconftool-2 --set --type=bool /desktop/gnome/url-handlers/irc/need-terminal false
    This is what I tried in lxde:
    $ yaourt -Sy mime-type xdg-utils
    $ xdg-mime default konversation.desktop application/irc
    $ xdg-mime default konversation.desktop x-scheme-handler/irc
    $ xdg-mime default konversation.desktop application/x-xdg-protocol-irc
    $ nano /usr/share/applications/kde4/konversation.desktop
    MimeType=application/irc;x-scheme-handler/irc;x-xdg-protocol-irc
    $ nano /usr/share/mime/packages/irc.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
    <mime-type type="application/irc">
    <comment>irc url</comment>
    <magic priority="50">
    <match value="%irc://-" type="string" offset="0"/>
    </magic>
    <alias type="application/irc"/>
    </mime-type>
    </mime-info>
    $ update-mime-database /usr/share/mime/
    I appreciate every suggestion. I`ll be on the road for two days and will try your suggestions on the weekend and will give feedback.
    Please explain as understandable as possible, at best with all commands and paths to the files - this is the newbie corner, right?
    Thanks in advance
    Tom
    Last edited by archtom (2011-06-15 19:44:57)

    really noone? Would be so glad if anyone could help!
    Last edited by archtom (2011-06-20 20:21:06)

  • Xdg-open is slow opening files

    Whenever I use xdg-open to open an application it takes a while until the application is shown, but if I try to open it with the application itself it works almost instantaneously. While using xdg-open I can notice a high increase of the cpu usage.
    What could it be that's causing this issue? Is there maybe a log file I can check to see what's going on under the hood? This issue is happening with gpicview (for images), nemo, and thunar; I haven't tried with other applications but I assume it's going to be the same.
    As relevant info I might add that I'm using openbox and no desktop environment. I'll upload any config files if requested, but I don't really know what to include as a start besides my mimeapps.list:
    #~/.local/share/applications/mimeapps.list
    [Default Applications]
    inode/directory=Thunar.desktop
    image/png=gpicview.desktop
    [Added Associations]
    image/png=gpicview.desktop;
    I've checked the wiki for xdg-open and all the forums (arch and outside of arch) and have just found people with the same issue, but no answers whatsoever.
    Any help on this would be much appreciated.

    After analyzing the loop (and the inner search_desktop_file function), I can tell that function is what's taking all the CPU time, also I can tell that only 3 iterations of the loop are run, one for each X, which have the values:
    $x_1 = Thunar.desktop /home/josep/.local/share/
    $x_2 = Thunar.desktop /usr/local/share/
    $x_3 = /usr/share/
    I can tell the first two searches take close to no time, and actually, the binary /usr/bin/thunar, which is located in the third iteration, doesn't take much time either, so surprisingly what's eating most of CPU resources is this part of the script:
    command="$(get_key "${file}" "Exec" | first_word)"
    command_exec=`which $command 2>/dev/null`
    arguments="$(get_key "${file}" "Exec" | last_word)"
    arg_one="`echo "$arg" | sed 's/[&*\\]/\\\\&/g'`"
    icon="$(get_key "${file}" "Icon")"
    if [ "${icon}" != "" ]
    then
    icon="--icon '${icon}'"
    else
    icon="''"
    fi
    # FIXME: Actually LC_MESSAGES should be used as described in
    # http://standards.freedesktop.org/desktop-entry-spec/latest/ar01s04.html
    localised_name="'$(get_key "${file}" "Name")'"
    arguments_exec="$(echo "$arguments" | sed -e 's*%[fFuU]*"'"$arg_one"'"*g' \
    -e 's*%i*'"$icon"'*g' \
    -e 's*%c*'"$localised_name"'*g')"
    The first two variables command and command_exec are set to "thunar" and "/usr/bin/thunar", and this happens relatively fast (although it takes some time to find it, it's not even a 10% of the total time).
    EDIT: I think all signs lead to the disk read taking too long (for example the get_key function which reads the .desktop file looking for the asked key, takes too much), but this is weird, as I had never encountered this issue in other linux distributions, everything has ran always smooth and fine, despite not having a good machine.
    EDIT2: After finally tracking down the issue, I've found this loop: (inside the get_key function)
    while read line
    do
    echo "readline" 1>&2
    case "$line" in
    "[Desktop Entry]")
    desktop_entry="y"
    # Reset match flag for other groups
    desktop_entry=""
    # Only match Desktop Entry group
    if [ -n "${desktop_entry}" ]
    then
    echo "${line}" | grep -E "^${key}=" | cut -d= -f 2-
    fi
    esac
    done < "${file}"
    More than 90% of CPU time is spent in this function, but I can't see why. Parsing a .desktop file is not a difficult task by any means and even if this was reading the file every time, everything would be cached in the ram anyway, as modern OSs use paging for that matter (and by modern I mean not modern at all) and I'm well aware that linux does).
    So TL;DR I don't understand how can the simple task of parsing a .desktop file take more time than opening google chrome or gimp. Any help on that?
    Last edited by setzer22 (2014-07-27 19:07:43)

  • Xdg-open strange behaviour

    When I have no defaults.list and mimeapps.list, xdg-open opens text/plain with gvim. But when I create defaults.list in /usr/share/applications/ and add the following lines :
    [Default Applications]
    text/plain=emacs.desktop
    it opens text files with firefox.
    However, if I move /usr/share/applications/defaults.list to ~/.local/share/applications/mimeapps.list, it opens text files with emacs as expected.
    What is happening with xdg-open?

    Thanks for this quick reply. Yes, the $ is present in the real path and yes, mapping seems to work. If it is this easy, why doesn't the default file>open work, this looks like a bug? It is not that userfriendly if every user (hundreds) should map there own drive letter to get this to work.

  • [SOLVED] Chromium not calling xdg-open

    Hi,
    I have been trying to get Chromium to call external applications based on their name and/or mime type. My desktop is XFCE.
    I have read about setting up the xdg-utils, and believe I have it configured. The following command line when run from bash opens up acroread and displays the PDF:
    xdg-open http://cran.r-project.org/doc/manuals/R-intro.pdf
    My ~/.local/share/applications/defaults.list file is:
    application/pdf=acroread.desktop;
    But when I click on the link in chromium I get the "Save File" dialog.
    As a test, I edited the /usr/bin/xdg-open shell script, and made it write to a file in /tmp when ever it is called. (The second line where I send the date to the /tmp/xdg-open.log file.)
    #!/bin/sh
    /usr/bin/date >> /tmp/xdg-open.log
    # xdg-open
    # Utility script to open a URL in the registered default application.
    # Refer to the usage() function below for usage.
    # Copyright 2009-2010, Fathi Boudra <[email protected]>
    When I try and download a PDF in chromium, it never adds to the /tmp/xdm-open.log file. (But does if I call it from the command line as I did above.)
    So to me, it looks like chromium isn't even calling the xdg-open script.
    Any one have any ideas?
    Thanks in advance.
    Last edited by landzend (2012-11-16 10:54:29)

    hiciu wrote:
    Hello,
    For me, chromium is not using xdg-open. You can verify it with:
    strace -e process chromium
    Then download something and try to open it from chromium. As for solution, try this: install perl-file-mimeinfo package and setup it with 'mimeopen --ask-default some-pdf-file.pdf'.
    landzend wrote:
    I have read about setting up the xdg-utils, and believe I have it configured. The following command line when run from bash opens up acroread and displays the PDF:
    xdg-open http://cran.r-project.org/doc/manuals/R-intro.pdf
    This is separate issue, it should run browser (http:// protocol), not acroread. Check this link: http://hiciu.org/some-pdf-file.pdf (harmless). All you know before you open it is the url, not the file type.
    Thanks. I already had the "perl-file-mimeinfo" installed.
    Yes. The link you gave above is type "image/jpeg", so the browser has to start the download to even know what it has coming.

  • [solved] Xdg-open to open everything with file manager

    I like to screw around with my system constantly and xdg-utils is an annoying utility to have to constantly fiddle with. I know there is a way to get xdg-open to open everything with the default file manager, but my google fu has failed me. As of right now I use pcmanfm, and I'm fairly certain I'm sticking with it for the long haul.
    Last edited by shamanstk (2010-05-11 17:57:15)

    Mr.Elendig wrote:perl-file-mimeinfo installed?
    This helped with a xdg-open anomaly. Before installing perl-file-* packages, pcmanfm used to open everything in firefox (which is set as default browser in xdg-open). Thought could be helpful to anyone having problems with applications using xdg-open.
    Last edited by shemz (2010-08-03 15:02:52)

  • Linopen - Yet another xdg-open replacement

    Inspired by Taylorchu's mimi, I decided to make xdg-open replacement written in bash that has somewhat flexible configuration.
    You can match either, extensions, mime types, mime groups, or regular expressions of the filename.
    You can also specify applications that you wish to open in terminal, and linopen knows when the process should be opened in new terminal or in your current open terminal.
    Example configuration
    # linopen configuration
    # enviroiment variables can be used
    # Specify your terminal emulator here
    # for terminal support.
    terminal=xterm
    # Specify all programs you want to
    # open in terminal like this:
    interm=vim
    # There are 4 ways to match filetypes.
    # The following examples are in the order
    # which linopen chooses the program as well.
    # 1. File extension
    # .png:sxiv
    # .mp4:mplayer
    # .txt:vim
    # 2. Mime type
    # image/png:sxiv
    # video/mp4:mplayer
    # text/plain:vim
    # 3. Mime category
    image:sxiv
    video:mplayer
    audio:mplayer->interm # you can also specify the interm rule explictly after '->'
    text:vim
    # 4. Regexp
    # Match some protocols by default
    ?'^http:\/\/':$BROWSER
    ?'^https:\/\/':$BROWSER
    ?'^www.':$BROWSER
    # Directory rule for directories
    # ideally you want to use file manager
    # here if you are a GUI user.
    directory:echo
    # Default rule just echoes back whatever
    # was feed. If you are using DE you could
    # just map a file manager here and it would
    # integrate with your system.
    default:echo
    PKGBUILD here
    Refer to the configuration file for more detailed how-to.
    There is also 'open' symlink to xdg-open to emulate Mac Os X behaviour.
    Last edited by Cloudef (2012-07-17 16:08:41)

    In this case it would be better to change the PKGBUILD to this
    # Maintainer: Cloudef <[email protected]>
    # Intelligent and suckless replacement for xdg-open
    pkgname=linopen
    pkgver=1.0
    pkgrel=1
    pkgdesc='Intelligent and suckless replacement for xdg-open'
    arch=('any')
    url='http://cloudef.eu'
    license=('WTFPL')
    provides=('xdg-utils')
    conflicts=('xdg-utils')
    backup=('etc/linopen.conf')
    source=('xdg-open' 'linopen.conf')
    package() {
    cd "$srcdir"
    mkdir -p "${pkgdir}/usr/bin"
    mkdir -p "${pkgdir}/etc"
    ln -s "/usr/bin/xdg-open" "$pkgdir/usr/bin/open"
    install -m755 xdg-open "${pkgdir}/usr/bin/"
    install -m755 linopen.conf "${pkgdir}/etc/"
    md5sums=('f5487fc4c305a20124da7bb164e6b04d'
    '2c9078f3ee82d619dc150bb44837d9e8')
    or (imho nicer) with this package function
    package() {
    install -Dm755 "$srcdir/xdg-open" "${pkgdir}/usr/bin/xdg-open"
    install -Dm755 "$srcdir/linopen.conf" "${pkgdir}/etc/linopen.conf"
    ln -s "/usr/bin/xdg-open" "$pkgdir/usr/bin/open"
    Last edited by Army (2012-07-03 16:04:13)

  • How to tell firefox to always use xdg-open?

    Firefox has always been a pain when it comes to file associations. It's very annoying to specify which program I want to open a specific file type everytime - especially when I have to find the program in /usr/bin every time. Is there any way to make firefox use xdg-open or exo-open for ANY file type?

    By modifying the source code? Should be easy to do. Or maybe there is a patch for this somewhere (but I haven't found one when I was looking for it).

Maybe you are looking for

  • New infinity connection not working.

    So I had the openreach engineer round yesterday to upgrade me to infinty. When he finished installing the kit he speed checked the line and got me to test the phone and broadband was working and everything was fine. Within 15 minutes of him leaving I

  • VGA CRT will not "wake up"... help please.  Reset display settings?

    Hello everybody, I have a mirror drive doors G4 Tower, Dual 1.25 GHz. I have an ADC and a DVI out from the computer. Just had damage to my old studio display so I am attempting to use just one CRT running from the DVI... w/ a DVI to VGA adapter. The

  • Problem in using the microphone in a Motorola HT820

    Hello, I'm trying to use the microphone in a Motorola HT820 bluetooth headset/headphones. It works well when I use just headphones, so I don't have any problem when I listen. However, when I use Skype or audio recording applications, the microphone d

  • How to split large video files into multiple individual clips by date

    Hello. I'm looking for a freeware/shareware program (if one exists, or willing to pay for one if it does this well) that will: 1) Analyze a large AVI file identifying the start/start points of each segment of video and the dates the video segments we

  • CRYPTO-4-PKT_REPLAY_ERR: decrypt: replay check failed

    Center router is cisco 7300 : Cisco IOS Software, 7301 Software (C7301-ADVIPSERVICESK9-M), Version 15.1(4)M2 branch router is cisco1900: Cisco IOS Software, C1900 Software (C1900-UNIVERSALK9-M), Version 15.1(4)M4, RELEASE SOFTWARE (fc1) one branch ro