2

Im trying to find a way to get list of active applications with names and icons of them.

Actually, I'm using this command to get all active processes.

wmctrl -lp

Sample output:

0x03800002  0 3293   user-notebook XdndCollectionWindowImp
0x03800007  0 3293   user-notebook unity-launcher
0x02c0000a  0 3471   user-notebook Desktop
0x03800011  0 3293   user-notebook unity-panel
0x03800016  0 3293   user-notebook unity-panel
0x0380001b  0 3293   user-notebook unity-dash
0x0380001c  0 3293   user-notebook Hud
0x04400001  0 3838   user-notebook Google - Google Chrome
0x04e00041  0 4159   user-notebook App - [~/Projects/app] - PhpStorm 2017.1.4
0x05400001  0 4231   user-notebook Slack - HelloCh
0x05a00001  0 7909   user-notebook Skype for Linux Beta
0x06400001  0 15203  user-notebook Spotify
0x06c000b6  0 4819   user-notebook [Screenshot from 2017-10-30 15-03-56] (imported)-1.0 (RGB color, 1 layer) 3286x1080 – GIMP

Now I don't know how to get icons of each process. Also I don't like names of processes, It would be awesome to get real names of apps eg. instead of:

Stack Overflow - Where Developers Learn, Share, & Build Careers - Google Chrome

I want real app name only:

Google Chrome

Can't use regex, because all apps are giving different kind of titles.

Is there any way to get this work, using unix commands only or bash scripts?

Basically I want to get same data like in app switcher in ubuntu (ALT+TAB)

Thanks

sebbz
  • 554
  • 3
  • 11
  • With respect to icons, see also: https://standards.freedesktop.org/icon-theme-spec/icon-theme-spec-latest.html – bishop Oct 30 '17 at 14:40
  • For an example of how you might interrogate the WM, see also: https://github.com/mkropat/jumpapp – bishop Oct 30 '17 at 14:43

1 Answers1

0

If you are using gnome then can use the following solution.

Full Disclosure: The github link bellow is my project.

Please look at https://github.com/blueray453/gnome-utils-by-blueray453/blob/main/appFunctions.js

function GetRunningApps() {

    let apps = Shell.AppSystem.get_default().get_running();

    var appsJsonArr = [];
    apps.forEach(function (a) {
        let icon_val = "";

        if (a.get_icon()) {
            icon_val = a.get_icon().to_string();
        }

        appsJsonArr.push({
            app_name: a.get_name(),
            app_id: a.get_id(),
            app_pids: a.get_pids(),
            app_icons: icon_val
        });

    })

    return JSON.stringify(appsJsonArr);
}

You need gnome extension to access data about running apps. You see the Shell.AppSystem, you can not import Shell is gjs or python.

Please check Could not find Meta, Shell & St in Python's GTK bindings which gnome extension documentaion has.

If you install this extension then the command you would run is:

dbus-send --print-reply=literal --session --dest=org.gnome.Shell /org/gnome/Shell/Extensions/GnomeUtilsApps org.gnome.Shell.Extensions.GnomeUtilsApps.GetRunningApps | jq .
Ahmad Ismail
  • 11,636
  • 6
  • 52
  • 87