Ubuntu – List Installed Applications Grouped By Type

alacartecommand line

I want a list of the applications installed in my system, however, I only want the ones listed as per the start menu.

I am not interested in a list of packages / dependencies etc so the following is not that helpful:

 dpkg --get-selections | grep -v deinstall

This is a bit closer.

for app in /usr/share/applications/*.desktop; do echo "${app:24:-8}"; done

However, the names don't match exactly what is in the menu and it doesn't meet my other criterion of grouping them.

e.g. I want to see

Graphics
     GIMP Image Editor

not

gimp

So to summarise, what I am looking for is a way to save to a text file what Alacarte displays.

Best Answer

The python script below reads the (English or international*) interface names from all desktop files in /usr/share/applications, as well as their Categories -section. It lists all found applications, according to their categories. Since many applications do have multiple categories, applications can appear in more than one category.

If the application has no Categories= mention, it is mentioned in the Uncategorized -section down in the list.

*Note Some applications (like Thunderbird) have an extensive list of interface names, for each and every language. This script, as it is, reads the first interface name, which is the internationally used one. The script can be altered to read the name in a specific language (if present), or automatically read the system's language, but that would need a bit more extensive coding :)

To use it:

Copy the script below, past it into an empty file, save it as applist.py. run it by the command (in a terminal window):

python3 /path/to/script/applist.py

The script:

#!/usr/bin/env python3
import os

uncategorized = []
categories = []
data = []
for item in os.listdir("/usr/share/applications"):
    if item.endswith(".desktop"):
        with open("/usr/share/applications/"+item) as data_source:
            lines = data_source.readlines()
        interface_name = [l.replace("\n", "").replace("Name=", "") \
                          for l in lines if l.startswith("Name=")][0]
        if len([l for l in lines if l.startswith("Categories")]) == 0:
            uncategorized.append(interface_name)
        else:
            subcats = [item for item in [l.replace("\n", "").replace(
                "Categories=", "") for l in lines if l.startswith(
                    "Categories=")][0].split(";") if item != ""]
            data.append([interface_name, subcats])
            categories = categories + subcats
categories = sorted([item for item in set(categories)])
for item in categories:
    applications = [subdata[0] for subdata in data if item in subdata[1]]
    print(item)
    for app in applications:
        print("   "+app)
print("Uncategorized")
for item in uncategorized:
    print("    "+item)

To give an impression of the output:

A small section of my output:

Audio
   Audacity
   MuseScore
   PulseAudio Volume Control
   Rhythmbox
AudioVideo
   Cheese
   VLC media player
   Audacity
   Rhythmbox
   MuseScore
   Videos
   OpenShot Video Editor
   Brasero
   PulseAudio Volume Control
   Rhythmbox
AudioVideoEditing
   Audacity
   MuseScore
   OpenShot Video Editor
BoardGame
   Mahjongg
Calculator
   Calculator