Ubuntu – Key for expanding Application menu in Gnome-Classic for 14.04

14.04gnome-classicmetacity

  1. In Gnome-Classic (metacity) in 14.04,

    • is there a key to invoke the Applications menu?
    • is there a key to switch between the items on the top panel, such as the Applications menu, Places, wireless icon, battery, time,
      shutdown/suspend/logout/lock menu, …?
  2. If possible, How shall I add the key for Application menu?

    To add a key for bringing out application menu, what is the command for doing that?

  3. Unlike https://askubuntu.com/a/133915/1471, there is no key for the
    Applications menu in my case.

    My 14.04 comes with compiz+unity, and then I install
    metacity+gnomeclassic. Do they share the same keyboard settings? Is
    that the reason why I don't have key for the Application menu?

    enter image description here

Thanks!

Best Answer

With a dirty workaround, it can be done quite well. Using xdotool, you can make it move the mouse to the position of the Applications menu, open it and automatically move back to its original position.

Since all happens very quickly and the mouse is moved back to its original position, you won't notice it.

enter image description here

The script assumes your Applications menu is in the upper left corner, like in the image above. If that is not the case, the coordinates in cmd1 have to be altered.

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

cursordata = subprocess.check_output(["xdotool", "getmouselocation"]).decode("utf-8").split()
loc = [d.split(":")[1] for d in cursordata[:2]]
cmd1 = "xdotool mousemove 10 5"; cmd2 = "xdotool click 1"; cmd3 = "xdotool mousemove "+(" ").join(loc)
for cmd in [cmd1, cmd2, cmd3]:
    subprocess.Popen(["/bin/bash", "-c", cmd])
    time.sleep(0.05)

In detail:

fetch the current mouse position:

cursordata = subprocess.check_output(["xdotool", "getmouselocation"]).decode("utf-8").split()

Parse the output (x/y) into coordinates:

loc = [d.split(":")[1] for d in cursordata[:2]]

Run the commands [cmd1, cmd2, cmd3] to subsequently:

  • move the mouse to the Applications menu
  • click
  • move the mouse back to wherever it was
for cmd in [cmd1, cmd2, cmd3]:
    subprocess.Popen(["/bin/bash", "-c", cmd])
    time.sleep(0.05)

How to use the script

  1. Install xdotool:

    sudo apt-get install xdotool
    
  2. Paste the script into an empty file, save it as open_appmenu.py

  3. Test-run it with the command:

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

    python3 /path/to/open_appmenu.py
    

Move to the other items

Once you opened the Applications menu, you can simply switch to the next item with the arrow keys.


Edit: generalized version

Below a version of the script that can be used in a flexible way, to click on the screen on any position, to be changed easily. The script can be run with two options:

  1. to set (remember) the current mouse location:

    run_click -set
    
  2. to click on the last-remembered position:

    run_click -run
    

If no position was set, a zenity message appears, inviting to set a position:

enter image description here

The script creates a hidden file; ~/.run_click where it stores the latest remembered coordinates.

As a test, I put both commands under the key combinations: Ctrl+Alt+R, and Ctrl+Alt+A, making it easy to change the click position on the spot.

How to set up

  1. like in the first script, Install xdotool:

    sudo apt-get install xdotool
    
  2. copy the script below into an empty file, save it as run_click (no extension) in ~/bin (create the directory if necessary) and make the script executable.

  3. If you just created ~/bin, run source ~/.profile.
  4. Test both commands, first run_click -set, then run_click -run to see if all works as expected.
  5. Add both commands to two different key combinations: choose: System Settings > "Keyboard" > "Shortcuts" > "Custom Shortcuts". Click the "+" and add the commands.

The script

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

option = sys.argv[1]
datafile = os.path.join(os.environ["HOME"], ".run_click")

def get_mousepos():
    cursordata = subprocess.check_output(["xdotool", "getmouselocation"]).decode("utf-8").split()
    return [d.split(":")[1] for d in cursordata[:2]]

if option == "-run":
    try:
        data = open(datafile).read()
        coords = (" ").join([l for l in data.splitlines()])
    except FileNotFoundError:
        message = "Please run the command: 'run_click -set' first, to set the click position"
        subprocess.Popen(["zenity", "--info", "--text", message])
    else:
        cmd1 = "xdotool mousemove "+coords; cmd2 = "xdotool click 1"; cmd3 = "xdotool mousemove "+(" ").join(get_mousepos())
        for cmd in [cmd1, cmd2, cmd3]:
            subprocess.Popen(["/bin/bash", "-c", cmd])
            time.sleep(0.05)
elif option == "-set":
    open(datafile, "wt").write(("\n").join(get_mousepos()))
Related Question