2

I wish to customize keyboard shortcuts for apps that are pinned to my unity launcher (in Ubuntu 16.04). What is the command line to execute (say) the second pinned app? The third (etc.)?

Any hint will be much appreciated.


Edit 1

As pointed by @CelticWarrior, Super + 1-9 should do the trick. For some reason, these bindings stopped working when I upgraded to 16.04 (worked fine in 14.04). That's why I wished to re-customize shortcut appropriately.


Edit 2

Compiz Config Settings Manager let me assign Super + Alt to view the Dash. Adding a 1-9 now launches the pinned apps. (Will not let me simply assign Super to view the Dash, though... resetting to default simply unassigns the key.)

6
  • 1
    Super + 1-9 ... Your example would be Super + 2. – user589808 Jan 9 '17 at 21:10
  • Thanks @CelticWarrior. For some reason, Super + 1-9 stopped working when I upgraded to 16.04 (worked fine in 14.04). That's why I wish to re-customize shortcut appropriately... Any clue? – emagar Jan 9 '17 at 21:32
  • @emagar does your Super key work at all ? does it bring up the Dash ? – Sergiy Kolodyazhnyy Jan 16 '17 at 3:30
  • 1
    Also, please don't post duplicate questions: askubuntu.com/q/863512/295286 If you want to attract attention to your question, ask someone to put bounty on it on Ask Ubuntu Meta – Sergiy Kolodyazhnyy Jan 16 '17 at 3:35
  • 3
    @emagar The Super+Number shortcuts work just fine for me in both 16.04 and 16.10. – Seth Jan 16 '17 at 3:38
1

Addressing the core issue

So far the cause of your issue with Super+number keys remains unknown, but I strongly believe that you would need to check whether the Super key is enabled under Unity Plugin in Compiz Config Settings Manager. ( obtainable via sudo apt-get install compizconfig-settings-manager command).

Command-line approach would be via this command:

dconf reset /org/compiz/profiles/unity/plugins/unityshell/show-launcher

Addressing the title question

However, to address the title question that you have, namely whether there is a command-line tool for open a program from Unity launcher . . . well, there wasn't a tool like that until now. The script given below performs exactly that function.

Usage

As given by -h option:

$ ./open_launcher_item.py -h                                                                                             
usage: open_launcher_item.py [-h] -i ITEM

optional arguments:
  -h, --help            show this help message and exit
  -i ITEM, --item ITEM  position of app on the launcher

So if you wanted to launch first app on the launcher, do

./open_launcher_item.py -i 0

If you want second item,

./open_launcher_item.py -i 1

To make the script work, store it in ~/bin folder. If you don't have bin folder in your /home/USER folder, then create one. Ensure the script is executable via chmod +x ~/bin/open_launcher_item.py command, or by right-clicking on the file in graphical file manager, and checking "Allow executing as program" under Permissions tab.

To make it work for keyboard shortcut, you will have to create like 9 shortcuts, and for each one of them set appropriate command , with -i 0, -i 1, and so forth until -i 9. Please note, that you will need to use full path to the script, i.e. /home/USER/bin/open_launcher_item.py -i 1

Script Source

Also available on GitHub

#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Author: Serg Kolo , contact: 1047481448@qq.com
# Date: January 15th, 2017
# Purpose: opens applications on Unity launcher according to position
# Tested on: Ubuntu 16.04 LTS
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gio,Gtk
import sys,argparse

class ApplicationOpener(Gtk.Application):

    def __init__(self):
        Gtk.Application.__init__(self,flags=Gio.ApplicationFlags.HANDLES_COMMAND_LINE)
        self.args = None 
        self.schema = 'com.canonical.Unity.Launcher'
        self.key = 'favorites'

    def gsettings_get(self, schema, path, key):
        """Get value of gsettings schema"""
        if path is None:
            gsettings = Gio.Settings.new(schema)
        else:
            gsettings = Gio.Settings.new_with_path(schema, path)
        return gsettings.get_value(key)

    def get_launchers(self):
        return [ i.replace('application://',"")  
                 for i in self.gsettings_get(self.schema,None,self.key)
                     if i.startswith('application://')
        ]

    def do_activate(self):
        position = self.args.item
        launchers = self.get_launchers()

        if position > len(launchers):
            position = -1

        try:
            Gio.DesktopAppInfo.new(launchers[position]).launch_uris(None)
        except Exception as e:
            subprocess.call(['zenity','--error','OOPS! SOMETHING WENT WRONG:\n' + str(e)])
        return 0

    def do_command_line(self, args):
        parser = argparse.ArgumentParser()
        parser.add_argument('-i', '--item',
                            type=int,required=True,
                            help='position of app on the launcher')
        self.args = parser.parse_args(args.get_arguments()[1:])
        self.do_activate()
        return 0

def main():

    app = ApplicationOpener()
    exit_status = app.run(sys.argv)
    sys.exit(exit_status)

if __name__ == '__main__':
    main()
4
  • Thanks @Serg! I inspected CCSM under the launcher tab and, as you suggest, the <Super> key is not assigned to show the Dash, Launcher and Help overlay. Oddly, it will only let me choose a key combination (eg. <shift>+<super>). f I assign <Super> on its own, the setting goes almost immediately back to 'Disabled'. What am I doing wrong? – emagar Jan 17 '17 at 19:15
  • 1
    @emagar There should be an option to reset it to default. I'm not on my laptop right now, so can't post a screenshot. Try to find that and if it works - great. If not, we can use command-line to reset that value. I'll update my answer once i get to my laptop. – Sergiy Kolodyazhnyy Jan 17 '17 at 19:22
  • Tried that @Serg, but reset button appears to default to <unassigned>... Maybe a command line reset might do the trick. – emagar Jan 17 '17 at 20:23
  • 1
    @emagar sorry for the delay. I added the command to my answer, dconf reset /org/compiz/profiles/unity/plugins/unityshell/show-launcher – Sergiy Kolodyazhnyy Jan 19 '17 at 14:50

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.