Useful bash scripts for wine / need help

Open forum for end-user questions about Wine. Before asking questions, check out the Wiki as a first step.
Forum Rules
Locked
landeel
Level 2
Level 2
Posts: 34
Joined: Sun May 18, 2008 11:49 am

Useful bash scripts for wine / need help

Post by landeel »

They can be copied to /usr/bin

The first script will extract icons from the .EXE file, choose the best icon, convert it to PNG, and copy it to the same folder of the application.

The second one depends on the first. It and can be very useful. If you simply call "wine-createshortcut MYAPP.EXE" it will produce a shortcut for the application, in desktop and applications menu, with the proper icon. :)

wine-extracticon

Code: Select all

#!/bin/bash
# wine-extracticon

echo "Extracting icon(s)..."
wrestool -x -t 14 "$( readlink -f "$@")" > "/tmp/$( basename "$( readlink -f "$@")").ico"

echo Converting icon to PNG...
convert -alpha on "/tmp/$( basename "$( readlink -f "$@")").ico" "/tmp/$( basename "$( readlink -f "$@")").png"

#  the script will assume the best icon is the bigger one
echo Copy $(ls -S -1 "/tmp/$( basename $( readlink -f "$@"))"*".png" | tac | tail -n 1) to "$( readlink -f "$@").icon.png" ...
cp $(ls -S -1 "/tmp/$( basename $( readlink -f "$@"))"*".png" | tac | tail -n 1) "$( readlink -f "$@").icon.png"

echo "Done."

wine-createshortcut

Code: Select all

#!/bin/bash
# wine-createshortcut

echo Extract icon...
wine-extracticon "$@"

echo Create shortcut contents...
myshortcut="[Desktop Entry]"\\n"Exec=wine start /Unix \""$( readlink -f "$@")"\""\\n"Type=Application"\\n"Categories=Application"\\n"Icon="$( readlink -f "$@")".icon.png"

echo Create .desktop file...
echo -e $myshortcut >"$( readlink -f "$@")".desktop

echo Create links on desktop and applications menu...
ln -s "$( readlink -f "$@").desktop" "$HOME/Desktop/$( basename "$( readlink -f "$@")").desktop"
ln -s "$( readlink -f "$@").desktop" "$HOME/.local/share/applications/$( basename "$( readlink -f "$@")").desktop"

echo Done.

The problem is both scripts will fail if there are any spaces in the filename or in the path name. Spaces in filenames are evil!

Any bash script experts? I need help!
eps
Level 3
Level 3
Posts: 87
Joined: Tue Mar 18, 2008 11:44 pm

Useful bash scripts for wine / need help

Post by eps »

On Fri, May 7, 2010 at 7:39 AM, landeel <[email protected]> wrote:
The first script will extract icons from the .EXE file, choose the best icon, convert it to PNG, and copy it to the same folder of the application.

The second one depends on the first. It and can be very useful. If you simply call "wine-createshortcut MYAPP.EXE" it will produce a shortcut for the application, in desktop and applications menu, with the proper icon. :)
These are pretty cool. Thanks!
doh123
Level 8
Level 8
Posts: 1227
Joined: Tue Jul 14, 2009 1:21 pm

Post by doh123 »

I need to find a way to do those... haven't looked into it. Sadly the tools you are using there doesn't exist for me (on OSX)... must be Linux only.
landeel
Level 2
Level 2
Posts: 34
Joined: Sun May 18, 2008 11:49 am

Post by landeel »

You need Imagemagick and icoutils. I don't know if those packages are available for OSX.
Charles Davis

Useful bash scripts for wine / need help

Post by Charles Davis »

On 5/7/10 2:35 PM, landeel wrote:
You need Imagemagick and icoutils. I don't know if those packages are available for OSX.
To the best of my knowledge, ImageMagick is, icoutils isn't.

Chip
landeel
Level 2
Level 2
Posts: 34
Joined: Sun May 18, 2008 11:49 am

Post by landeel »

http://www.nongnu.org/icoutils/
I think icoutils can be compiled for OSX.
doh123
Level 8
Level 8
Posts: 1227
Joined: Tue Jul 14, 2009 1:21 pm

Post by doh123 »

landeel wrote:http://www.nongnu.org/icoutils/
I think icoutils can be compiled for OSX.
you'd think.. but I get all kinds of syntax errors and stuff...
lahmbi5678
Level 7
Level 7
Posts: 823
Joined: Thu Aug 27, 2009 6:23 am

Post by lahmbi5678 »

regarding the whitespace problem (unfortunately the shell uses lists separated by spaces for $@), you can find several solutions there:

http://stackoverflow.com/questions/3010 ... -loop-list
vitamin
Moderator
Moderator
Posts: 6605
Joined: Sat Feb 23, 2008 2:29 pm

Re: Useful bash scripts for wine / need help

Post by vitamin »

landeel wrote:The problem is both scripts will fail if there are any spaces in the filename or in the path name. Spaces in filenames are evil!
You have few issues with your scripts:
1. Don't use readlink - you don't need to dereference symlinks yourself
2. $@ expands into list of arguments, not one argument. So you do need to use $1 instead. Or merge all of them (see below)
3. Make sure you quote filename passed to your scripts eg:

Code: Select all

wine-extracticon "file name with spaces"
4. Use variables

A simple workaround for 2 & 3 is:

Code: Select all

FILE=$1
shift
for i in $@; do FILE="$FILE $i"; done
landeel
Level 2
Level 2
Posts: 34
Joined: Sun May 18, 2008 11:49 am

Post by landeel »

1. Don't use readlink - you don't need to dereference symlinks yourself
I need the scripts to work in 3 cases:

1) wine-createshortcut /media/sdaX/Programs/myapp.exe (Absolute paths. Useful when launching the script from a file manager.)

2) wine-createshortcut myapp.exe (For files in the current directory. Useful when you're in console.)

3) wine-createshortcut ./Programs/myapp.exe (Relative paths. Useful when you're in console too.)

readlink will always resolve anything to the absolute path. It will simply work in all 3 cases, so I see no reason for not using it.

Apart from that, thank you very much for your tips! It seems to work now. :)
landeel
Level 2
Level 2
Posts: 34
Joined: Sun May 18, 2008 11:49 am

Post by landeel »

Code: Select all

#!/bin/bash
# wine-extracticon

echo Usage : wine-extracticon myapp.exe

MYFILE=$(readlink -f "$1")
shift
for i in $@; do MYFILE="$MYFILE $i"; done
MYBASENAME=$(basename "$( readlink -f "$MYFILE")")

echo "Extracting icon(s)..."
wrestool -x -t 14 "$MYFILE" > "/tmp/$MYBASENAME.ico"

echo Converting icon to PNG...
convert -alpha on "/tmp/$MYBASENAME.ico" "/tmp/$MYBASENAME.png"

#  the script will assume the best icon is the bigger one
echo Copy "$(ls -S -1 "/tmp/$MYBASENAME"*".png" | tac | tail -n 1)" to "$MYFILE.icon.png" ...
cp "$(ls -S -1 "/tmp/$MYBASENAME"*".png" | tac | tail -n 1)" "$MYFILE.icon.png"

echo "Done."

Code: Select all

#!/bin/bash
# wine-createshortcut

echo Usage : wine-createshortcut myapp.exe

echo Extract icon...
wine-extracticon "$@"

MYFILE=$(readlink -f "$1")
shift
for i in $@; do MYFILE="$MYFILE $i"; done
MYBASENAME=$(basename "$( readlink -f "$MYFILE")")

echo Create shortcut contents...
myshortcut="[Desktop Entry]"\\n"Exec=wine start /Unix \""$MYFILE"\""\\n"Type=Application"\\n"Categories=Application"\\n"Icon="$MYFILE.icon.png""

echo Create .desktop file...
echo -e $myshortcut >"$MYFILE".desktop

echo Create links on desktop and applications menu...
ln -s "$MYFILE.desktop" "$HOME/Desktop/$MYBASENAME.desktop"
ln -s "$MYFILE.desktop" "$HOME/.local/share/applications/$MYBASENAME.desktop"

echo Done.
JamesJ
Newbie
Newbie
Posts: 1
Joined: Thu Aug 25, 2011 1:35 am

Post by JamesJ »

ImageMagick itself compiles fairly easily on OS X, but it’ll end up missing JPEG support, which was kind of a bummer.
pquiring
Newbie
Newbie
Posts: 2
Joined: Tue Oct 06, 2009 9:23 am

winelnk.exe

Post by pquiring »

I've uploaded a simple tool to create lnk/desktop files for pre-installed apps.

http://bugs.winehq.org/show_bug.cgi?id=29491

It's a simple app that uses Win32 API to create a lnk which in turn causes Wine to create the desktop file for you (including the icon).

Enjoy!
Locked