1

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?

2
  • Hi Norbert. is not enough to put xdg-open on the exec line with %F?
    – jpbrain
    Commented Sep 9, 2021 at 16:24
  • Thanks, @jpbrain, It is not enough, as .exe application reads data from its directory.
    – N0rbert
    Commented Sep 9, 2021 at 18:54

2 Answers 2

1

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
1
  • 1
    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.
    – N0rbert
    Commented Sep 9, 2021 at 19:09
1

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/ .

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .