[Wine] File association in wine

occhigrigi wineforum-user at winehq.org
Tue Apr 28 05:36:58 CDT 2009


Hello everybody, i've made a little script that associates every extension known by linux in wine, unless the extension isn't already associated to some other program. So you can doubleclick on a file from winefile and have it opened with the corresponding linux application.
It's a quick and dirty script that generates a .reg file, it isn't freedesktop compliant, i am a KDE and only KDE user  [Wink] 

The script reads the global mime database located at /usr/share/mime/globs, merges it with the user database located at /usr/share/mime/globs then generate an extension.reg file.
Every extension is associated to a "kdestart.exe" script that you can put somewhere in the PATH and customize as you like (and maybe make it freedesktop.org compliant  [Wink] )

Here's the script (copy and paste in a file, make it executable and run it)

WINEPREFIX=${WINEPREFIX:-$HOME/.wine}
FILEOUT=extension.reg
echo REGEDIT4 > $FILEOUT
echo >> $FILEOUT
for ext in `cat $HOME/.local/share/mime/globs /usr/share/mime/globs | grep  "*."|cut -f 2 -d :|sort --unique -f | cut -f 2 -d "*"`; do
    ext2=`echo $ext|cut -f 2- -d .`
    esiste=`grep -i '\\[Software\\\\\\\\Classes\\\\\\\\'$ext'\\]' $WINEPREFIX/system.reg | wc -l`
    if [ $esiste == "0" -a $ext != $ext2 ] ; then
        echo Aggiungo estensione $ext $ext2
        echo "[HKEY_CLASSES_ROOT\\"$ext"]" >> $FILEOUT
        echo @=\"$ext2.document\" >> $FILEOUT
        echo "[HKEY_CLASSES_ROOT\\"$ext2".document]" >> $FILEOUT
        echo @=\"$ext2.document\" >> $FILEOUT
        echo "[HKEY_CLASSES_ROOT\\"$ext2".document\\shell]" >> $FILEOUT
        echo "[HKEY_CLASSES_ROOT\\"$ext2".document\\shell\\open]" >> $FILEOUT
        echo "[HKEY_CLASSES_ROOT\\"$ext2".document\\shell\\open\\command]" >> $FILEOUT
        echo @=\"C:\\\\windows\\\\command\\\\start.exe kdestart.exe \\\"%1\\\"  >> $FILEOUT
        echo >> $FILEOUT
    fi
done


Once run, merge the resulting file to the registry (regedit extension.reg)

And here's the kdestart.exe script, put it where it can be found ($HOME/bin or /usr/local/bin) and make it executable

#!/bin/bash
echo $@ >> $HOME/kdestart.log
i=`winepath -u "$@"`
echo $@ $i >> $HOME/kdestart.log
kfmclient exec "$i"
#------------------------------------------------------------------

The last line, i.e. the command used to launch ISN'T freedesktop compliant and can be executed only under KDE.

Hope this can be useful to someone.







More information about the wine-users mailing list