3

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.

  • This could be an application. Will require some serious coding. But as a starter, see this command which gives application followed by the categories it comes in for f in /usr/share/applications/*.desktop; do echo -n $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 I would suggest you have a look at the code of the GUI app/launcher you use. – Registered User Jul 1 '14 at 3:41
3

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
| improve this answer | |
  • Very good. Thanks! Some slight differences to what is shown in the menu though. e.g. Deluge is listed in this script in the P2P category whereas in Alacarte it is listed under Internet. – opticyclic Jul 3 '14 at 8:31
  • @opticyclic You are right! I think alacarte makes its own summary of the categories, mentioned in the desktop files. Now you mention it, I also notice that in some cases, not the Name= line is used as an interface name, but the X-GNOME-FullName=line (e.g. Name=Screen Reader / X-GNOME-FullName=Orca Screen Reader). I think I will work on this script a little more later (and post it here). I think it is interesting enough to do so, and matches my interest in general :). – Jacob Vlijm Jul 3 '14 at 10:22
3

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

| improve this answer | |
  • +1 for a short bash solution. Not 100% what I was looking for (as you say - not real name) and much slower than the python implementation posted, but very interesting nonetheless! – opticyclic Jul 3 '14 at 8:24
0

If you run this:

dpkg-query -W --showformat='${Package} ${Version} ${Section}\n' > filesystem.manifest

Then filesystem.manifest looks like this:

abiword-common 2.9.2+svn20120213-1 editors
accountsservice 0.6.15-2ubuntu9.7 admin
acl 2.2.51-5ubuntu1 utils
acpi-support 0.140.1 admin
acpid 1:2.0.10-1ubuntu3 admin
activity-log-manager-common 0.9.4-0ubuntu3.2 utils
activity-log-manager-control-center 0.9.4-0ubuntu3.2 utils
adduser 3.113ubuntu2 admin
adium-theme-ubuntu 0.3.2-0ubuntu1 gnome

This shows all details of an application.

apt-cache show zim
| improve this answer | |
  • I said in the post that I wan't interested in a list of packages! I want the list of applications in the menu (GnoMenu?). Do you have items like this in your menu? qt4-linguist-tools 4:4.8.4+dfsg-0ubuntu18.3 devel – opticyclic Jun 30 '14 at 23:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.