1

I'm writing a script to quickly list my many opened windows. I have grouped them according to their class. I would like to add an icon to the group.

I use wmctrl to get the list of windows:

wmctrl -lx | egrep -v "0x.*(0 N/A)|-1" | sort -k3

The egrep pipe filters out background services.
the sort of the third column groups the windows by class.

This is a sample output:

0x05a00001  0 google-chrome.Google-chrome  ubunzeus (8) Newest Questions - Ask Ubuntu - Google Chrome
0x05a00028  0 google-chrome.Google-chrome  ubunzeus How to get the icon of a window class? - Ask Ubuntu - Google Chrome
0x06c00010  0 Mail.Thunderbird      ubunzeus Inbox - L. D. James - Mozilla Thunderbird

The window class is the third column of the output.

If I can access the icon (in this sample, google-chrome.Google-chrome and Mail.Thunderbird), I can associate the image with those blocks.

Does anyone know where the Ubuntu stores these images? I believe they are referred to as the mime images or something like that.

L. D. James
  • 25,036

2 Answers2

1

While I'm sure there are more elegant and official methods, I have found a workaround to get the icon.

You can locate the icons associated with the applications by searching the desktop launcher and viewing the icon= entry.

In the `` example in the question, you would search the name after the the "." dot, which is Google-chrome.

This commandline will provide the Desktop Launcher:

$ egrep -ir "\b$Google-chrome\b" /usr/share/applications/*.desktop ${HOME}/.local/share/applications/*.desktop | head -1

This will give the Chrome desktop launcher:

/usr/share/applications/google-chrome.desktop

Now search for the icon entry:

$ egrep -i "icon=" /usr/share/applications/google-chrome.desktop
Icon=google-chrome

In this case, the launcher not having a full path, you can find it's the icon of the current theme, which can be found with a python script provided by Stefano Palazzo.

L. D. James
  • 25,036
0

Pass the wm_class as argument to the following function.

#!/usr/bin/env gjs

const { Gio } = imports.gi;

let icon = Gio.AppInfo.get_all().find(a => a.get_startup_wm_class() == ARGV[0]).get_icon().to_string();

print(icon);