Score:1

How to create desktop-launcher for .exe application which should be launched using wine inside its directory?

zw flag

I have an MS Windows application which needs new version of Wine. I have installed it locally to home-folder using PlayOnLinux.

I'm stuck with creating simple bash/dash/sh script to launch .exe application inside its folder. I tried standard pushd/popd, cd && exec, (cd && exec) approach but it failed.

What I need:

  • Desktop-file as launcher for a script

  • A script which:

    1. changes directory to .exe application's directory
    2. executes wine .exe inside application directory

Currently I'm happy with the following Python-code for wrapper script (to be placed in /usr/local/bin/wine32-wrapper):

#!/usr/bin/python3
import os
import sys
import subprocess

if len(sys.argv) >= 2:
    path = sys.argv[1]
    wd = os.path.dirname(path)
    exec_path = ["/home/{}/.PlayOnLinux/wine/linux-x86/6.15/bin/wine".format(os.getenv('USER'), path), "{}".format(path)]
    p = subprocess.run(exec_path, cwd=wd)
else:
    print("\nUsage {} with one argument - full file path.".format(sys.argv[0]));

and .desktop-file (to be placed in ~/.local/share/applications/wine32.desktop), for it:

#!/usr/bin/env xdg-open
[Desktop Entry]
Version=1.0
Type=Application
Terminal=false
Icon=mate-panel-launcher
Exec=wine32-wrapper %f
Name=Local Wine32-6.15

then I associate my exe-files with this wine script using Caja.

Is it possible to replace above python script with bash/dash/sh script with exactly same functionality?

jpbrain avatar
ca flag
Hi Norbert. is not enough to put xdg-open on the exec line with %F?
N0rbert avatar
zw flag
Thanks, @jpbrain, It is not enough, as .exe application reads data from its directory.
Score:1
cn flag

For the Desktop entries there is a Path parameter available. Here is how the StarCraft II launcher (created during the installation by Wine) looks like:

[Desktop Entry]
Name=StarCraft II
Exec=env WINEPREFIX="/home/spas/.wine" /opt/wine-staging/bin/wine C:\\\\windows\\\\command\\\\start.exe /Unix /home/spas/.wine/dosdevices/c:/users/Public/Desktop/StarCraft\\ II.lnk
Type=Application
StartupNotify=true
Comment=Play StarCraft II
Path=/home/spas/.wine/dosdevices/c:/Program Files (x86)/StarCraft II
Icon=89A5_StarCraft II.0
StartupWMClass=starcraft ii.exe
N0rbert avatar
zw flag
The problem here is that `Path` is dynamic. I can't predict from which directory user will launch the .exe. Imagine the situation where .exe reads its .ini (or DB, or some resource) from the same directory.
Score:1
zw flag

After some more deeper analysis I found good and interesting desktop-files for "Wine Windows Program Loader" which came from Wine packages. It has special options in Exec field:

Exec=wine start /unix %f

and forces exe-file to be launched in its directory.

For my case it may be adapted for ~/.local/share/applications/wine32.desktop as shown below:

#!/usr/bin/env xdg-open
[Desktop Entry]
Version=1.0
Type=Application
Terminal=false
Icon=mate-panel-launcher
Exec=/home/user/.PlayOnLinux/wine/linux-x86/6.15/bin/wine start /unix %f
Name=Local Wine32-6.15

Thus the script part is not needed, we end with single desktop-file with special start /unix option.

Note: when Wine is installed from official Ubuntu repositories such "Wine Windows Program Loader" can be registered using commands like mkdir -p ~/.local/share/applications/ && cp /usr/share/doc/wine-stable/examples/wine.desktop ~/.local/share/applications/ .

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.