Windows exe icons under GNOME

This post explains how to configure GNOME and a file browser that supports thumbnailers (such as Nautilus) to generate icons embedded inside Windows executables.

Dependencies: icoutils (can be found in most repositories).

This guide will allow your file browser (Nautilus is used in this guide, but with some amendments other browsers supporting external thumbnailers should work) to automatically extract and generate GNOME-compatible icons for Windows executables.

We’ll use a combination of wrestool and icotool, provided by icoutils. First we will create a bash script to utilise these two binaries, since GNOME will only execute simple commands as thumbnailers, but not bash script or similar.

As root, create an empty file in /usr/bin named ‘msiconailer’ (or whatever you want to call your thumbnailer) then copy and paste this code into the contents of the file using a text editor:

#!/bin/bash
export size=$3
lines=$(wrestool -x -t 14 "$1" | icotool -l - | sed 's/--width=//g' - | sed 's/--height=//g' - | sed 's/--bit-depth=//g' - | sort -nrk 3 -k 5 | sed 's/--icon --index=[0-9]* //' | sed 's/ .*//')
for line in $lines; do
if [ $line -le $size ]; then
size=$line
break
fi
done
wrestool -x -t 14 "$1" | icotool -x --width=$size -o "$2" -

This code first extracts a list of icon sizes from the exe specified by the first argument  passed to the script ($1), and matches the icon closest in size to that which is requested by the thumbnailer (the third argument $3). These binaries can include multiple cursors/icons in different sizes, so we need to use wrestool to make sure we get the one we want. We then use wrestool to actually extract the icon. The data for this icon will be passed to stdout by wrestool, which we then pipe into icotool, which converts this data into a PNG format image and writes it to disk in the location specified as the second argument ($2). Here’s an example use of our script:

msiconailer /path/to/windows.exe /path/to/exportedicon.png 64

Once you’ve saved the script (and don’t forget to make it executable), we can configure our thumbnailer in GNOME.

The thumbnailers are configured inside gconf-editor (you can access this via the Applications menu or just enter gconf-editor into a terminal). The specific path to the thumbnailers is /desktop/gnome/thumbnailers – but to add new keys here we must use the terminal. Execute these two commands in the terminal:

gconftool-2 --type=bool --set "/desktop/gnome/thumbnailers/application@x-ms-dos-executable/enable" true
gconftool-2 --type=string --set "/desktop/gnome/thumbnailers/application@x-ms-dos-executable/command" "/usr/bin/msiconailer %i %o %s"

Your thumbnailer has been added – browse to a Windows executable using Nautilus to see icons generated.

If your exe icons don’t appear, don’t forget to empty the .thumbnails/fail folder in your home directory, and make sure things are configured correctly in Nautilus preferences (such as abandoning thumbnail-generation for files over a certain size or residing in a remote location).

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.