List Installed Applications Grouped By Type

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

The following script will give the output much similar to what you want.

var=$(echo $(for f in /usr/share/applications/*.desktop;do cat $f|grep -i categories|sed -e 's/Categories=//g;s/\;/\n/g';done|sort|uniq))
for n in $var
do
  echo $n
  for f in /usr/share/applications/*.desktop
  do
    echo -e -n "\t" $f|sed -e 's!/usr/share/applications/!!g;s/.desktop/::/g'
    echo $(cat $f |grep -i categories|sed -e 's/Categories=//g;s/\;/:/g')
  done |grep -i :$n: |sed s/'::.*'//
done

Will give output as

...
Development
     bluefish
     boa-constructor
     eclipse
     gambas3
     GNUSim8085
     python2.7
     python3.2
     qtcreator
     ubuntusdk
DiscBurning
     brasero
     furiusisomount
Documentation
     yelp
...

Explanation

  • var: stores the list of all possible categories.
  • The inner for loop finds list of applications that contains the category as provided by outer for loop. The inner for loop also outputs everything required.

I also tried another script which outputs the real name(GIMP Image Editor) rather than package name(gimp) but it gives weird results because some desktop files do not contain newlines