Ubuntu – How to stop opening an application exit you out of the Activities Overview

activities-overviewconfigurationcustomizationgnomegnome-shell-extension

I often need to go into the Activities Overview and open many applications so it is rather annoying if every time I click to open an application I am taken out of the AO and to that application, though this is useful on some occasions, I would prefer to stay in the AO and whatever part of it I am in.

Can this be done? Perhaps there is an extension to achieve this? Preferably I would like to be able to SHIFT click or something on an application in order to open it but not take me out of the AO, so that it is easier for me when I don't need it.

I am running Ubuntu GNOME 16.04 with GNOME 3.20.

Best Answer

An slightly edited version of this script allows multiple selection of applications at once:

enter image description here

The script

#!/usr/bin/env python3
import subprocess
import os

dr = "/usr/share/applications"

apps = []

for f in [f for f in os.listdir(dr) if f.endswith(".desktop")]:
    try:
        content = open(dr+"/"+f).read()
        if not "NoDisplay=true" in content:
            lines = content.splitlines()
            name = [l for l in lines if l.startswith("Name=")][0].replace("Name=", "")
            command = [l for l in lines if l.startswith("Exec=")][0].replace("Exec=", "")
            comment = [l for l in lines if l.startswith("Comment=")]
            comment = comment[0].replace("Comment=", "") if comment else "No description"
            apps.append([name, command, comment])
    except:
        pass

apps.sort(key=lambda x: x[0]); apps = sum(apps, [])
displ_list = '"'+'" "'.join(apps)+'"'

try:
    chosen = subprocess.check_output([
        "/bin/bash",
        "-c",
        'zenity --list '+\
        '--multiple '+\
        '--column="Applications" '+\
        '--column="commands" '+\
        '--column="Description" '+\
        '--hide-column=2 --height 450 '+\
        '--width 500 '+\
        '--print-column=2 '+displ_list
        ]).decode("utf-8").split("|")
    for item in chosen:
        item = item.strip()
        item = item[:item.rfind(" ")] if "%" in item else item
        subprocess.Popen([
            "/bin/bash", "-c", item
            ])
except subprocess.CalledProcessError:
    pass

To use

  • Copy the script below into an empty file, save it as list_apps.py
  • Test- run it by the command (open a terminal window, type the command and press Return):

    python3 /path/to/list_apps.py
    
  • If all works fine, add it to a shortcut key: choose: System Settings > "Keyboard" > "Shortcuts" > "Custom Shortcuts". Click the "+" and add the command:

    python3 /pat/to/list_apps.py
    

    to a shortcut key combination you like.

Explanation

The script lists all .desktop files in /usr/share/applications, and checks if the line NoDisplay=true is in the file (which means it is not meant to be used as a GUI). Then it looks into the files, looks up the application name and the command to run it.

The difference with the linked answer is mainly the fact that the zenity window is set to allow multiple selections.

Related Question