1

This link: https://unix.stackexchange.com/questions/509360
It explains how to add a program to the Wine menu:

wine winemenubuilder /path/to/link.lnk

But I don't have a .lnk file for my particular program.
How do I create the .lnk file?

Mario Palumbo
  • 277
  • 2
  • 8
  • 36

1 Answers1

1

I invented the right solution that guarantees perfect compatibility with wine:

lnk () {
    cat <<EOF > /tmp/shortcut.vbs
Set FSO = CreateObject("Scripting.FileSystemObject")
TargetPath = FSO.GetAbsolutePathName(WScript.Arguments(0))
WorkingDirectory = FSO.GetParentFolderName(TargetPath)
Set lnk = CreateObject("WScript.Shell").CreateShortcut(WScript.Arguments(1))
    lnk.TargetPath = TargetPath
    lnk.WorkingDirectory = WorkingDirectory
    lnk.Save
EOF
    wine wscript '//B' 'Z:\tmp\shortcut.vbs' "$@" 2> /dev/null
    local exit_code=$?
    sync; rm -f /tmp/shortcut.vbs; sync
    return $exit_code
}

I was able to call the function cleanly:

lnk 'C:\Program Files (x86)\Rufus\rufus.exe' 'C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Rufus.lnk'

This is the installation function of a program in my case:

update_rufus () {
    local old_version="$(cat ~/'.wine/dosdevices/c:/Program Files (x86)/Rufus/version.txt' 2> /dev/null)"
    local link="$(wget -q 'https://api.github.com/repos/pbatard/rufus/releases/latest' -O - | grep '"browser_download_url":' | grep -o -m 1 -E '[^"]+/rufus-[0-9.]+\.exe')"
    wget -q "$link" -O rufus.exe
    local exit_code=$?
    if [[ $exit_code -eq 0 ]]; then
        mkdir -p ~/'.wine/drive_c/Program Files (x86)/Rufus'
        echo "$link" | perl -lpe 's|^.*/rufus-([0-9.]+)\.exe$|\1|' > ~/'.wine/drive_c/Program Files (x86)/Rufus/version.txt'
        mv rufus.exe ~/'.wine/drive_c/Program Files (x86)/Rufus'
        lnk 'C:\Program Files (x86)\Rufus\rufus.exe' 'C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Rufus.lnk'
        local new_version="$(cat ~/'.wine/dosdevices/c:/Program Files (x86)/Rufus/version.txt')"
        if [[ "$new_version" == "$old_version" ]]; then
            echo "Rufus is already the newest version ($new_version)."
        else
            echo "Rufus has been successfully updated ($new_version)."
        fi
    else
        echo 'An error has occurred.'
    fi
    return $exit_code
}
Mario Palumbo
  • 277
  • 2
  • 8
  • 36