Script that lists all available applications from the menu

Forum Forums General Tips and Tricks Script that lists all available applications from the menu

  • This topic has 13 replies, 6 voices, and was last updated Feb 24-2:01 pm by Dave.
Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #99561
    Member
    PPC

      I wanted to do something like this for years – it can greatly increase the speed of ToolbarIcon Manager, and basicly any bash script that needs to list info from .desktop files- to make it perfect I’ll have to find a way to include the “exec” and “icon” fields… For now it’s a great little script:
      (NOTE: I now nothing about python…)

      #!/bin/bash
      #This script generates a (localized) list of all available FreeDesktop applications
      #Adapted by PPc from https://unix.stackexchange.com/questions/344188/list-all-desktop-files-that-appears-in-application-menu
      export bashvar=100
      
      cat << EOF > /tmp/pythonscript.py
      #!/usr/bin/python
      import subprocess
      from gi.repository import Gio
      
      all_apps = Gio.AppInfo.get_all()  # Returns a list of DesktopAppInfo objects (see docs)
      
      # For example, print display name of all apps with description and .desktop file name, using "|" to divide the fields
      for app in all_apps:
          print(app.get_display_name()) , "|", (app.get_description()), "|", (app.get_filename())
      
      EOF
      
      chmod 755 /tmp/pythonscript.py
      
      /tmp/pythonscript.py > /tmp/applist.txt
      cat /tmp/applist.txt| sort > /tmp/sorted_applist.txt
      cat /tmp/sorted_applist.txt

      Edit: according to https://developer-old.gnome.org/glibmm/unstable/classGio_1_1DesktopAppInfo.html#a06a665d4d812adb2eeb5c05d4c91c266 ,
      the variable (app.get_executable()) should give us the Exec field from the .desktop file. But it only gets me the first word (ex: in “sudo firefox”, it returns only “sudo”)

      • This topic was modified 2 months, 2 weeks ago by PPC.
      • This topic was modified 2 months, 2 weeks ago by PPC.
      #99564
      Member
      PPC
        Helpful
        Up
        0
        ::

        Result of this code- please test the new IceWM Toolbar Icon Manager- that should load much faster, specially on older computers…

        EDIT: this version of the script works only with python 2.Z (antiX 19 and below). For an updated version, please see my post below!

        • This reply was modified 2 months, 2 weeks ago by PPC.
        #99603
        Moderator
        Brian Masinick
          Helpful
          Up
          0
          ::

          Result of this code- please test the new IceWM Toolbar Icon Manager- that should load much faster, specially on older computers…

          I tried to add the “Weather” with this version and it didn’t work. I tried adding a couple of other apps, no go. The previous version worked for me fine. (referring to the other toolbar script for IceWM – that one works fine and still does).

          I can see the listings you created, but as far as actually adding, removing, or doing anything else to the IceWM toolbar, your script in the other topic works great; unfortunately I can’t figure out what this one does or is supposed to do; it definitely does not change anything in my .icewm configuration.
          Sorry, this didn’t help with anything I’ve been able to spot on my system.

          • This reply was modified 2 months, 2 weeks ago by Brian Masinick.

          --
          Brian Masinick

          #99608
          Member
          PPC
            Helpful
            Up
            0
            ::

            Many thanks for trying to test the script! This was my first effort, and it worked only with python 2.X…
            On the link below is a script that works with python 2.X and 3.X (antiX 19 and below, antiX 21 and above)

            https://www.antixforum.com/forums/topic/beta-new-faster-version-of-icewm-toolbar-icon-manager/#post-99581

            #99610
            Moderator
            Brian Masinick
              Helpful
              Up
              0
              ::

              Yes, I agree. The version in your link works great. We’re on the same page.
              Nice job in the working version and congratulations on your success with Python!

              --
              Brian Masinick

              #99628
              Forum Admin
              Dave
                Helpful
                Up
                0
                ::

                Interesting point; this is the base utility app-select uses to retrieve the list and information for the apps in the list.
                I think app.get_executable() should actually be app.getExec().
                Here is a list of the functions to get the different parts/columns in app-select

                appexec = DesktopEntry(filename).getExec()
                 appname = iftype+DesktopEntry(filename).getName()
                 appgname = DesktopEntry(filename).getGenericName()
                 appicon = DesktopEntry(filename).getIcon()
                 appdesc = DesktopEntry(filename).getComment()
                 appterm = DesktopEntry(filename).getTerminal()
                 appcategories = DesktopEntry(filename).getCategories()
                 appcategories = str(appcategories)
                 appcategories = appcategories.replace("'", "").replace("[", "").replace("]", "")
                

                It has been a while since I have run a timing function on app-select, but I think most of the slow down is within building the gtk window / treeview itself rather than retrieving the .desktop information. Though there is a fair bit of the time used spent on locating icons. The desktop-menu script also uses this in conjunction with the xdg module for parsing xdg menu files and structures along with the .desktop files.

                Computers are like air conditioners. They work fine until you start opening Windows. ~Author Unknown

                #100168
                Forum Admin
                Dave
                  Helpful
                  Up
                  0
                  ::

                  I have removed the xdg modules from app select and updated / rewrote to be based solely off Gtk as mentioned above.
                  I am hoping that there are not many missing or fuzzy icons which I think was the reason xdg and pixmaps was used in the original along with Gtk.
                  Limiting virtualbox to one core at 50% execution cap during testing seemed to trim the time by 2/3. ~ 0.7s vs ~2.9s originally.

                  code is found here https://gitlab.com/antiX-Dave/app-select-antix/
                  running ./app-select after cloning should be enough to test.

                  If it is still quite slow I will look into caching again and changing the options parser (which accounted for ~0.4s in my testing).

                  Computers are like air conditioners. They work fine until you start opening Windows. ~Author Unknown

                  #100172
                  Forum Admin
                  anticapitalista
                    Helpful
                    Up
                    0
                    ::

                    @Dave – When opening an app from apt-select, it opens a terminal first even if the chosen app is a gui.
                    app-select definitely opens faster than before.

                    Philosophers have interpreted the world in many ways; the point is to change it.

                    antiX with runit - leaner and meaner.

                    #100173
                    Member
                    PPC
                      Helpful
                      Up
                      0
                      ::

                      @Dave – the Master strikes back!
                      Yes – on my slowest device, my netbook with an single core Atom CPU and 1Gb of RAM, app-select takes about 5-6 seconds to load. This new version took about 12 seconds to load for the first time, for some reason, but after that, it loads in a little over 3 seconds (yes, I timed it). That also applies when toggling columns on/off.
                      It’s quite nice already, but if it was possible to perform the changes you mentioned, and save a second more to it on slow devices, it would make this excellent tool really useful even on extremely slow devices (I run rofi, as my default App searcher/launcher, on my netbook, because it loads instantly, by force of some black art!!!)

                      Edit: beaten by anticapitalista once again – yes I noticed that apps always launch a terminal window… Some wrong flag maybe?

                      P.

                      • This reply was modified 2 months, 1 week ago by PPC.
                      • This reply was modified 2 months, 1 week ago by PPC.
                      • This reply was modified 2 months, 1 week ago by PPC.
                      #100182
                      Member
                      sybok
                        Helpful
                        Up
                        0
                        ::

                        @PPC: Perhaps, the faster run the second time is because relevant ‘*.pyc’ files were created.

                        #100186
                        Forum Admin
                        Dave
                          Helpful
                          Up
                          0
                          ::

                          Hmm, yes launching everything in terminal
                          this is because the new get_commandline() function does not return the terminal=true/false value, rather it returns the entire exec line. (whereas get_exec returns the base executable). I cannot see an immediate way to get the terminal= boolean value to use the default terminal app. Perhaps this is not needed anymore and it would be better to allow gtk stack to pick the terminal app? (it seems this is the case with htop as an example)

                          Computers are like air conditioners. They work fine until you start opening Windows. ~Author Unknown

                          #100514
                          Forum Admin
                          Dave
                            Helpful
                            Up
                            0
                            ::

                            Please try the newest version.
                            I did add the xdg module back in as I could not find a way to get the boolean value for Terminal= from the .desktop file using gio.appinfo. (If anyone knows a way; please share and I can remove the xdg module again. Manually parsing the .desktop file is much slower)
                            Always opening in terminal should now be addressed.
                            Also added a cache file as previously testing seemed to increase the speed with older hard disks after the first cache is built.
                            Once again code is found here https://gitlab.com/antiX-Dave/app-select-antix/

                            Computers are like air conditioners. They work fine until you start opening Windows. ~Author Unknown

                            #100520
                            Member
                            Robin
                              Helpful
                              Up
                              0
                              ::

                              If anyone knows a way; please share and I can remove the xdg module again. Manually parsing the .desktop file is much slower

                              sed -n 's/^Terminal=\(..*\).*$/\1/p' '/usr/share/applications/leafpad.desktop'
                              This one using sed is pretty fast for catching, but since your script is written in python, it might be a bit tricky to run sed from within. It is possible, if I remember correctly:
                              You can either run sed using something like

                              def getterminalstatus(filename):
                                  sed = subprocess.Popen(
                                      "sed", "-n", "..." ,filename,
                                      stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE,encoding='utf8')
                                  stdout,stderr = sed.communicate(text)
                                  if sed.returncode == 0: return stdout
                                  raise Exception(stderr)

                              Or you could make use of pythonsed which can be imported as module and used without the subprocess.Popen method. But the latter would just draw in another module instead of xdg, so it doesn’t make sense.
                              I’d check out whether it works fast enough using the supprocess.Popen method.

                              Windows is like a submarine. Open a window and serious problems will start.

                              #100526
                              Member
                              PPC
                                Helpful
                                Up
                                0
                                ::

                                @Dave – I tested this version the same way I tested the previous one- I downloaded the .zip of the source code, uncompressed it, and ran the app-select python script that was inside it. In complained it could not find the cache file (in ~/.cache/app-select)…
                                I tried running app-select-cache instead – it loads, and even on this multicore desktop, I notice it starts way faster than the default app-select- enough for me to consider it’s, for all intents and purposes, instant to load (and the default app-select already loaded pretty fast on it).
                                If I try to run the new app-select, after app-select-cahe, now I get:

                                overall start:0
                                after imports:0.13220667839050293
                                after options parser:0.296738862991333
                                /home/ppc/Transferências/app-select-antix-master22/app-select-antix-master/app-select:424: DeprecationWarning: Gtk.Widget.override_background_color is deprecated
                                  self.filter_message_box.override_background_color(Gtk.StateType.NORMAL, Gdk.RGBA(1,0.5,0.5,0.5))
                                before indexing:0.33028554916381836
                                Traceback (most recent call last):
                                  File "/home/ppc/Transferências/app-select-antix-master22/app-select-antix-master/app-select", line 550, in <module>
                                    win = mainWindow()
                                  File "/home/ppc/Transferências/app-select-antix-master22/app-select-antix-master/app-select", line 459, in __init__
                                    self.fill_treeview()
                                  File "/home/ppc/Transferências/app-select-antix-master22/app-select-antix-master/app-select", line 310, in fill_treeview
                                    self.filtered_store = self.make_store()
                                  File "/home/ppc/Transferências/app-select-antix-master22/app-select-antix-master/app-select", line 301, in make_store
                                    self.add_item(False, self.store, app, '')
                                  File "/home/ppc/Transferências/app-select-antix-master22/app-select-antix-master/app-select", line 228, in add_item
                                    appdesc = pieces[6]
                                IndexError: list index out of range

                                The same thing happens in my desktop with antiX 22 runit and my netbook with antiX 21, both full, 64bits.

                                And the terminal window still pops up, when I run app-select-cache.

                                On the netbook, running app-select-cache either takes about 10 seconds to load or is just marginally faster than the default app-select.

                                I don’t know python, but Robin’s idea to use sed on the selected .desktop file does seem like the ideal solution, if it works in python – I found this link, that may be helpful, on that: https://stackoverflow.com/questions/64696051/sed-command-in-python

                                Edit: on the faster desktop, the new script toggles columns on/off instantly, on the slower netbook, it seems to toggle faster than the original app-select.

                                I hope this tests help you, @Dave

                                P.

                                • This reply was modified 2 months, 1 week ago by PPC.
                                • This reply was modified 2 months, 1 week ago by PPC.
                                #100554
                                Forum Admin
                                Dave
                                  Helpful
                                  Up
                                  0
                                  ::

                                  Sorry PPC, should have noticed that but forgot to remove the cache file and test after adding the automatic cache refresh.
                                  That should be fixed now.

                                  As to sed, this is the same as directly parsing the file, it is slower than using the xdg module. That is why I am hoping for a way in Gio as it will already have the files read and in memory. Maybe the best way to speed this up would be to use C instead of python but I am not really that comfortable with C at the moment.

                                  edit:
                                  app-select-cache I need to remove, it was made to try caching a while ago to see the difference between the speed of the older app-select and the version of app-select with caching. The newer version has an option flag so you can just run it as normal which uses caching or add the –no-cache flag to disable caching.

                                  • This reply was modified 2 months, 1 week ago by Dave.

                                  Computers are like air conditioners. They work fine until you start opening Windows. ~Author Unknown

                                Viewing 15 posts - 1 through 15 (of 15 total)
                                • You must be logged in to reply to this topic.