Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This is easily done for a single file type, as answered in How to associate a file type within Wine with a native application?, by creating a .reg for the desired filetype. But this is for AVI only. I use some wine apps (uTorrent, Soulseek, Eudora, to name a few) that can launch a wide range of files. Email attachments, for example, can be JPG, DOC, PDF, PPS... its impossible (and not desirable) to track down all possible file types that one may receive in an email or download in a torrent.

So I neeed a solution to be more generic and broad. I need the file association to honor whatever native app is currently configured. And I want this to be done for all file types configured in my system.

I've already figured out how to make the solution generic. Simply replacing the launched app in .reg for winebrowser, like this:

"Content Type"="application/pdf"
@="C:\\windows\\system32\\winebrowser.exe \"%1\""

Ive tested this and it works correctly. Since winebrowser uses xdg-open as a backend, and converts my windows path to a Unix one, the correct (Linux) app is launched.

So I need a "batch" updater to wine's registry, sort of a wine-update-associations script that I can run whenever a new app is installed. Maybe a tool that can:

  • List all Mime Types types in my system that have a default, installed app associated
  • Extract all the needed info (glob, mime type, etc)
  • Generate the .REG file in the above format

The tricky part is: i've searched a LOT to find info about how association is done in Ubuntu 10.10 onwards, and documentation is scarce and confusing, to say the least. has no complete spec, and even Gnome docs are obsolete. So far I've gathered 4 files that contain association info, but im clueless on which (or why) to use, or how to use them to generate the .reg file:


Any help, script or explanation would be greatly appreciated!


share|improve this question
up vote 2 down vote accepted

Years later, I've made a small utility that scans MIME database (both system and user) and register all known native mime-types in Windows registry.

It uses xdg-open to open a file if there is a default (native) application for that mime type, otherwise uses packagekit to search for a package that can handle that file (just like what Nautilus does). So my initial requirement of registering only extensions that have an installed, native application was not needed anymore. However, an early version of the script did filter only such types. The snippet that made it possible was:

perl -e '
    use strict; use warnings;
    use File::MimeInfo::Magic; use File::MimeInfo::Applications;
    while (my $line = <STDIN>) {
      my ($ext, $mime) = (split/\t/, $line);
      my ($def, @apps) = mime_applications_all($mime);
      print "$line\n" if ($def || @apps)

By default my script only registers native types that have no handler in windows registry, but it can also override such associations (so, for example, jpeg files are opened in native viewer instead of the default Gecko wine browser). It can also ignore some extensions even if they have no handler in windows.

It tries its best to be winemenubuilder-friendly, meaning all associations it creates is not published as native associations (or as x-wine-extension mimetypes) by winemenubuilder, which would be ugly and potentially cause loops. This is very tricky and not yet perfect, specially with mixed-case extensions (.C and .c for example)

That said, I hope this script is helful for everyone:

Improvements welcome!

share|improve this answer
your script says it succeeded, but nothing in wine changed for me. No big problem, I found another workaround in the wine app Everything itself, but I just wanted to inform you – Blauhirn Jul 16 at 4:36


There is a wine bug about this - which is more of an improvement than a bug. The point is to have ShellExecute call xdg-open, and if not found, look for gnome and kde defaults. You should be able to apply the patch and finally have the magic :-). This solution is cleaner as it does not need messing with the registry.

To be more complete here is how to patch and compile wine from source.


I update the wine registry with the script below to add a list of common file types.
You can extend the list to add more types.
It makes use of /usr/bin/gnome-open in the gstart.exe file so it won't work for non-gnome desktops as is.

Put this in


FNKEY=/tmp/"key"$(date +%F_%H-%M-%S)".reg"

[ -e $FNKEY ] && { echo "temporary key file exists..try again"; exit 1; }

echo "copying gstart.exe"

echo "backing up the registry"
cp $REG $REG.$(date +%F_%H-%M-%S).old

echo "setting new wine registry keys"
for i in http doc docx ppt pptx xls xlsx odt ods xml txt pdf odt svg zip ; do {
    echo "setting $i"
"Content Type"="application/'$i'"
@="C:\\gstart.exe \"%1\""'
    echo "$key" > $FNKEY
    regedit $FNKEY

echo "done"

The gstart.exe is a bash script..and is the bridge to both worlds:


# logging, optional
LOG=$HOME/.wine/gstart.exe-log.$(id -u -n)
echo "[ $(date) ] $# argument(s) received: '$@'" > $LOG

# convert the path
RESULT=$(winepath "$@" 2> /dev/null)

# finally open the file


  1. copy gstart.exe in your current working directory before running as it will copy it to the .wine folder.
  2. the folder locations can be changed, e.g. gstart.exe doesn't have to sit in c:\.
  3. does no magic: new types have to be added manually. You could improve it to read the Linux files (mimeapps.list, ..) and update the wine registry if then needed.
  4. tested to work at least in wine1.4.

Wine FAQ: How do I associate a native program with a file type in Wine?

share|improve this answer
+1 for the effort, but this hardly solve my problem. First, there is little point using gnome-open over xdg-open, which I already mentioned in the question, and is far more portable. Second, hardcoding a few file extensions is insufficient for me: as I said, "I need the file association to honor whatever native app is currently configured. And I want this to be done for all file types configured in my system." And I'm aware this is tricky. It's the "magic" you mentioned in your note #3 that I'm interested in ;) – MestreLion Oct 8 '12 at 1:13
I guess I read your question a bit too fast the first.. I saw you are using xdg-open and I'll change it in my scripts. About the magic: one way would be to read iterate over all items in the mime files instead of having. But then you will have to run it every time you update your system as new extensions might have been added. That does not happen every day though. – rosch Oct 8 '12 at 17:41
Or even brutally set up a cronjob for the registry update..only modifying the registry if the mimes have been updated. – rosch Oct 8 '12 at 17:49
The tricky part is not when to update the registry, but how, or, more precisely, update for which file extentions? I don't know how to consistently parse the mime database to retrieve all the extensions that have a default, installed app associated. Or, as you said: how to read iterate over all items in the mime files? There are some mime types in my mimeapps.lst that I don't have installed here, and some point back to a Wine app (which would cause infinite loops) – MestreLion Oct 8 '12 at 22:13
Sorry about the English mistakes in my first comment, I edited it and it got messed up a bit.. Please read my EDIT in the answer, there you have the magic as all files are taken care of. – rosch Oct 9 '12 at 8:03

I have gathered Info all over the place and have found the following to work:

I have created a file called ~/.wine/drive_c/gstart.exe

with the following :

# logging, optional
LOG=$HOME/.wine/gstart.exe-log.$(id -u -n)
echo "[ $(date) ] $# argument(s) received: '$@'" > $LOG
# convert the path
RESULT=$(winepath "$@" 2> /dev/null)
# finally open the file

Then : Created a file called linuxnative.reg in my ~/bin

with the following :

"Content Type"="application/linuxnative"
"Content Type"="application/linuxnative"
"Content Type"="application/linuxnative"
"Content Type"="application/linuxnative"
"Content Type"="application/linuxnative"
"Content Type"="application/linuxnative"
"Content Type"="application/linuxnative"
"Content Type"="application/linuxnative"
@="c:\\gstart.exe \"%1\""

then you do a

regedit linuxnative.reg

Hope this helps.

share|improve this answer
Thanks for trying to help! But a hardcoded list of a few well-known extensions does not solve my problem. Also, the "info you gathered from all over the place" seems to be the same info already posted by me and rosch, including a copy-and-paste of his gstart.exe script. – MestreLion Aug 3 '14 at 22:36

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.