WINE tips: File associations for Windows applications in Linux (continued)

There is a downside to the approach described in my previous post regarding file associations for Windows applications run via WINE, at least in the case of KDE.

By using KDE’s ‘System Settings’ > ‘File Associations’ to change the application launch command from:

env WINEPREFIX="/home/fitzcarraldo/.wine-visio5" WINEARCH="win32" wine /home/fitzcarraldo/.wine-visio5/drive_c/Program\ Files/Visio/Visio32.EXE

to:

env WINEPREFIX="/home/fitzcarraldo/.wine-visio5" WINEARCH="win32" wine C:\\windows\\command\\start.exe /Unix %U

the launch command in KDE’s Kicker application launcher menu is also changed to the latter. Trying to launch the Windows application from the Kicker menu (Wine > Programs > a_Windows_application) then fails. Presumably this is because the wine command expects a filename (the %U in the command string) but that is not being provided.

Alternative 1

One solution is to use a shell script as described in my earlier post: WINE tips: How to associate IrfanView with an image file type in Linux. Kicker can still be used to launch the application (e.g. Wine > Programs > IrfanView) when the menu command is of the following form but no filename is provided (even though the %f is left in the command string):

/home/fitzcarraldo/launch_IrfanView.sh %f

Alternative 2

Another solution – well, really a work-around – is to accept that the Windows application cannot be launched from the Kicker menu and to create a separate Desktop Configuration File in /home/fitzcarraldo/Desktop/ which uses a different command to launch the application. For example, in my previous post the file association I configured via ‘System Settings’ > ‘File Associations’ for Visio was:

env WINEPREFIX="/home/fitzcarraldo/.wine-visio5" WINEARCH="win32" wine C:\\windows\\command\\start.exe /Unix %U

and therefore the command in the Kicker menu entry is the same, but I created a Desktop Configuration File which I named ‘/home/fitzcarraldo/Desktop/Visio 5 Professional‘ which contains the command:

env WINEPREFIX="/home/fitzcarraldo/.wine-visio5" WINEARCH="win32" wine /home/fitzcarraldo/.wine-visio5/drive_c/Program\ Files/Visio/Visio32.EXE

$ ls -la ~/Desktop/Visio*
-rwxrwxrwx 1 fitzcarraldo users 562 Aug 26 17:42 /home/fitzcarraldo/Desktop/Visio 5 Professional

Notice that the command to launch the Windows application does not contain a filename parameter (%U), so when I double-click on the icon on the Desktop it launches Visio.

Summary

Ideally, KDE should be changed to allow the application launching command in ‘System Settings’ > ‘File Associations’ to be edited to be different to the application launching command in the Kicker menu. In the absence of that, you have two alternatives in the case of WINE:

  1. Create a shell script to launch the application. This allows you to launch the Windows application via Kicker and by double-clicking on a file of the applicable type.

    or

  2. Create a separate Desktop Configuration File in e.g. the ~/Desktop/ directory. This allows you to launch the Windows application by double-clicking on a Desktop Configuration File for the application and by double-clicking on a file of the applicable type. However you cannot launch the application from its entry in the Kicker menu.

WINE tips: File associations of Windows applications in Linux

I have several applications for Windows installed under WINE in Linux. These applications launch correctly if I double-click on a file for that application, but, in the case of some of these applications, the file itself is not opened. Therefore I first have to launch the application and then load the file from within the application (File > Open, or whatever). Some time ago I explained how to fix this in the case of IrfanView by creating a shell script – see my post WINE tips: How to associate IrfanView with an image file type in Linux – but there is an easier way to do it in many cases, as illustrated by the example below for another Windows application I use regularly in Linux. I finally got fed up with not being able to open .vsd (Visio drawing) files by double-clicking on them in Linux, and decided to fix this. The same procedure applies, whatever the Windows application.

I use KDE, but the principle applies whatever Desktop Environment you are using. Just use the relevant File Association configuration tool for that Desktop Environment.

  1. I selected ‘System Settings’ > ‘File Associations’ from the KDE Kickoff menu launcher.

  2. I entered ‘vsd’ (without the quotes) in the search field in order to find the application associated with that file type.

    The ‘Known Types’ box then displayed the following:

    >- application

  3. When I expanded that by clicking on it, the ‘Known Types’ box displayed the following two application file types:

    v- application
            vnd.ms-visio.viewer
            vnd.visio

  4. Clicking on either displayed ‘Visio 5.0 Professional’ in the ‘Application Preference Order’ box. I selected it and clicked on ‘Edit…’, which opened a Properties window for the application’s desktop configuration file.

  5. I clicked on the ‘Application’ tab. The ‘Command’ box contained the following command:
    env WINEPREFIX="/home/fitzcarraldo/.wine-visio5" WINEARCH="win32" wine /home/fitzcarraldo/.wine-visio5/drive_c/Program\ Files/Visio/Visio32.EXE

    (The wine command itself has to be preceded by the definition of the WINEPREFIX and WINEARCH environment variables because I specified those environment variables originally when I installed the application via WINE.)

    I changed the command to be the following:

    env WINEPREFIX="/home/fitzcarraldo/.wine-visio5" WINEARCH="win32" wine C:\\windows\\command\\start.exe /Unix %U

    for both vnd.ms-viso.viewer and vnd.visio application file types, and clicked on ‘OK’ and ‘Apply’.

That’s all there was to it. Now when I double-click on any file ending with ‘.vsd’, Visio launches as before but the actual file is opened in the application. Very straightforward, and I really should have made the effort to fix it sooner. :-)

WINE tips: How to associate IrfanView with an image file type in Linux

In my previous post I showed how to install IrfanView with a WINEPREFIX. This time I’m going to show you how to associate IrfanView with a particular image file type so that IrfanView launches and opens a file of that type when you double-click on the file.

IrfanView is an excellent free (but not open-source) application for Windows, and I’ve been using it in Windows since 1997. But there are so many excellent image viewing and editing applications native to Linux that I’ve never needed or wanted to install IrfanView under WINE. GQview, Gwenview, KolourPaint and the GIMP have so far covered all my needs. Nevertheless, IrfanView is my favourite utility for viewing and manipulating image files in Windows, and I can understand why some people may want to run it in Linux.

The usual method of setting file associations in Linux does not work for IrfanView. For example, if you use KDE’s Kickoff > System Settings > File Associations to associate JPG files with IrfanView, IrfanView will indeed launch if you double-click on a JPG file, but you’ll be left staring at an empty IrfanView window, as if you had simply launched IrfanView directly.

However, there is a straightforward work-around for this problem, and it involves the use of a Bash script. You associate the file type with a Bash script that you create specifically to accept a Linux parameter for the file name and convert it to a format that WINE can pass to IrfanView when launching it. Here is how to do it.

I created a text file ~/launch_IrfanView.sh containing the following Bash script:

#!/bin/sh
File="z:"${1//\//\\}
wine "/home/fitzcarraldo/.wine-irfanview/drive_c/Program Files/IrfanView/i_view32.exe" $File

I used a WINEPREFIX of $HOME/.wine-irfanview/ when I installed IrfanView, so replace “.wine-irfanview” with “.wine” if you installed IrfanView without a WINEPREFIX (i.e. if it is installed in the ~/.wine/ directory tree).

I made the file executable:

$ chmod +x /home/fitzcarraldo/launch_IrfanView.sh

I then edited the command for ‘IrfanView 4.27′ in ‘Kickoff’ > ‘System Settings’ > ‘File Associations’ > ‘image’ > ‘jpeg’ > ‘Application Preference Order’ | ‘IrfanView 4.27′ > ‘Edit’ > ‘Application’ to be as follows:

/home/fitzcarraldo/launch_IrfanView.sh %f

That works fine: when I double-click on a JPG file in a Dolphin window, IrfanView launches and opens the file.

Of course, if you want IrfanView to be the default viewer for PNG files then you would perform the aforementioned steps for ‘Kickoff’ > ‘System Settings’ > ‘File Associations’ > ‘image’ > ‘png’.

As I wrote initially, there are several excellent image viewers and editors for Linux, so I did not keep IrfanView as my default image viewer in Linux. But I have left IrfanView installed under WINE, as I may yet want to use it under Linux at some point.

WINE tips: Giving each Windows application its own environment

I’m going to tell you about the useful WINEPREFIX environment variable, and, as a bonus, you’ll also find out how to install Office 2007 and IrfanView in WINE, plus how to configure file associations so that double-clicking on a .doc and/or .docx file will launch Word 2007 and open the file.

BACKGROUND

I’ll wager most WINE users have not heard of the WINEPREFIX environment variable and are installing all Windows applications in the ~/.wine/ directory tree. Until a couple of months ago that’s what I was doing too, but these days I install all Windows applications in WINE using this clever WINE feature.

Some WINE users will know that it is possible to use the ‘Add application…’ button on the Applications Settings page (the Applications tab) in the winecfg window to specify per-application libraries (DLLs) and graphics settings. For example, a user could use this feature in order to set an override of riched20 (native) for Office 2007 but not for, say, IrfanView. This WINE feature allows you to ‘ring fence’ applications from each other, avoiding the possibility of incompatible DLLs and graphics settings interfering with the working of another application. However, WINE still keeps directories and files for all the Windows applications in the ~/.wine/ directory tree.

The WINEPREFIX environment variable enables you to go a stage further. By using a WINEPREFIX you can install each Windows application (or a group of applications) in its own, completely separate environment. For example you could install IE7 in ~/.wine-ie7/, IrfanView in ~/.wine-irfanview/, World of Warcraft in ~/.wine-wow/, Word 2007 in ~/.wine-word2007/ and so on. You could even have different versions of the same Windows application installed simultaneously if you wanted. Not only does a WINEPREFIX allow you to keep an application’s DLLs and all settings completely separate from those of other applications, thus avoiding or preventing conflicts, it means that uninstalling a Windows application becomes as simple as:

$ rm -rf ~/.wine-visio5

You no longer need to hope that wine uninstaller supports the application, or that the application’s uninstaller will work if launched directly via WINE.

If winecfg’s Applications Settings allows you to partially isolate an individual application, the use of a WINEPREFIX allows you to put an application into solitary confinement!

HOW TO USE A WINEPREFIX

Let’s look at a couple of examples.

Installing Office 2007 (including SP2) with its own WINEPREFIX:

$ cd
$ export WINEPREFIX=$HOME/.wine-office2007
$ winecfg
$ cd .wine-office2007/drive_c/
$ wget http://www.kegel.com/wine/winetricks
$ chmod +x winetricks
$ cp ~/Downloads/X12-30107.exe . # Office 2007 installer from Microsoft.
$ cp ~/Downloads/office2007sp2-kb953195-fullfile-en-us.exe . # Office 2007 SP2.
$ cp ~/Downloads/officelp2007sp2-kb953195-fullfile-en-us.exe . # Office 2007 SP2 language pack.
$ wine X12-30107.exe # Install Office 2007. If you have an Office 2007 installation DVD then use "wine /path/to/setup.exe" instead.
$ winecfg # Set up riched20.dll as per instructions in Wine AppDB for Office 2007 (it must be "Native (Windows)").
$ ./winetricks msxml3 # Install msxml3 as per instructions in Wine AppDB for Office 2007, to stop SP2 crashing.
$ wine office2007sp2-kb953195-fullfile-en-us.exe # Install Office 2007 SP2.
$ wine officelp2007sp2-kb953195-fullfile-en-us.exe # Install Office 2007 SP2 language pack.
$ ./winetricks wsh56js # Install Windows Scripting Host for the thesaurus.
$ ./winetricks allfonts # Install all the TTF fonts.
$ winecfg # Set usp10 to 'native,builtin' for the equation toolbar in Word.
$ ./winetricks fontsmooth-rgb # Install font smoothing.

I have a KDE Kickoff menu entry Applications > Wine > Programs > Microsoft Office > Word containing the following command:

env WINEPREFIX="/home/fitzcarraldo/.wine-office2007" wine C:\\windows\\command\\start.exe /Unix /home/fitzcarraldo/.wine-office2007/dosdevices/c:/users/fitzcarraldo/Start\ Menu/Programs/Microsoft\ Office/Microsoft\ Office\ Word\ 2007.lnk

The above command might look complicated, but WINE creates it automatically during the installation of Office 2007. WINE also creates similar Kickoff Menu entries for the other Office 2007 applications.

Having installed Office 2007 using a WINEPREFIX, if I wanted to launch e.g. Word from the command line I’d need to enter the following commands:

$ export WINEPREFIX=$HOME/.wine-office2007
$ wine $WINEPREFIX/drive_c/Program\ Files/Microsoft\ Office/Office12/WINWORD.EXE

instead of the following if I had not installed Office 2007 using a WINEPREFIX:

$ wine $HOME/.wine/drive_c/Program\ Files/Microsoft\ Office/Office12/WINWORD.EXE

Installing IrfanView 4.27 with its own WINEPREFIX:

$ cd
$ export WINEPREFIX=$HOME/.wine-irfanview/
$ winecfg
$ cd .wine-irfanview/drive_c/
$ wget http://www.kegel.com/wine/winetricks
$ chmod +x winetricks
$ ./winetricks mfc42
$ cp ~/Downloads/iview427_setup.exe .
$ cp ~/Downloads/irfanview_plugins_427_setup.exe .
$ wine iview427_setup.exe
$ wine irfanview_plugins_427_setup.exe

I have a KDE Kickoff menu entry for IrfanView containing the following command:

env WINEPREFIX="/home/fitzcarraldo/.wine-irfanview" wine C:\\\\Program\\ Files\\\\IrfanView\\\\i_view32.exe

The above command might look complicated, but WINE creates it automatically during the installation of IrfanView.

By installing Office 2007 and IrfanView this way, I keep the DLLs installed by the IrfanView installer completely separate from the DLLs used by Office 2007.

File associations

If you find that Word opens a blank document (Document1) when you double-click on a .doc (or .docx) file then this is a file association issue. In KDE I simply selected Kickoff > System Settings > File Associations and changed all the associations for .doc and .docx from the following:

env WINEPREFIX="/home/fitzcarraldo/.wine-office2007" wine C:\\windows\\command\\start.exe /Unix /home/fitzcarraldo/.wine-office2007/dosdevices/c:/users/fitzcarraldo/Start\ Menu/Programs/Microsoft\ Office/Microsoft\ Office\ Word\ 2007.lnk

to the following:

env WINEPREFIX="/home/fitzcarraldo/.wine-office2007" wine C:\\windows\\command\\start.exe /Unix %U

A different approach is needed if you want IrfanView to open image files when you double-click on them, and I’ll cover that in my next post.

Follow

Get every new post delivered to your Inbox.

Join 51 other followers