3

Using Ubuntu 20.04, if I get a new notification on the notification bar, I would like to simply use a shortcut, such as Super+K, so the notification would quickly open instead of using the mouse to open it.

Is it possible to create something like this?

2 Answers2

4

It's a bit unclear if you want a keyboard shortcut to access the notification list or the currently active shortcut. Whichever the case, you don't need to add custom keyboard shortcuts for these tasks, as predefined ones already exist:

  • If you want to open the notification list, just press Super+V. You can move between items in this list using the arrow keys. You can also open a notification by selecting it and pressing Enter or you can remove a notification by selecting it and pressing Delete.

  • If you want to focus the currently active notification, just press Super+N.

If you would like to use other shortcuts for these tasks, open Settings → Keyboard shortcuts, search for the Show the notification list (green ellipse in the screenshot below) or Focus the active notification (red ellipse in the screenshot below) shortcut, respectively, and change them to whichever shortcuts you like.

Keyboard shortcuts

  • 1
    Ah you learn something new every day! Didn't really know about Super+N (didn't really need that much those shortcuts). Your answer indeed fits bets for OP's question. – Pizza Mar 29 '21 at 06:22
2

That's an interesting request, and we'll have to divide it to two different requests:

  1. Create a custom keyboard shortcut that executes a command in Ubuntu:
    If you're not familiar with this feature, this Ubuntu documentation will make it easy for you.
  2. Create a desktop environment mouse action automation (essentially control your mouse actions using commands).
    This can be done using the xdotool, which needs to be installed first, using the:
    sudo apt-get install -y xdotool command.

Using xdotool to move your mouse position to a specific location on screen:

Sending the xdotool a mousemove command argument, followed by our desired location will cause the mouse position to move onto that point on screen:

xdotool mousemove X Y

Where X is your horizontal position, and Y is your vertical position - the trick is to find where your notification appears, and choose a location that is inside the notification popup. (usually, 1000 70 is the default location, depending on your resolution and system settings).

How may I determine exactly where my notification appears?

You may use the notify-send command to invoke a notification!
The first argument would be the title, while the second argument is the body:

notify-send "my_title" "my_message"

Once the notification is gone, place a file or a folder in the middle of where it was, and start experimenting the xdotool command.
Whenever you've pointed over that file it would be highlighted, just as if you were hovering your mouse over files manually!

Final step - imitating a mouse hover on the notification so it expands:

If you've reached this part, you've probably noticed that the notification did not expand - that is because we also need to move our mouse a little on top of it to imitate a user's behavior of expanding it.

The solution? just use another xdotool mousemove command right after the first one was executed within the range of your notification pop up, for example:

xdotool mousemove 1000 70 && xdotool mousemove 900 70

If you see the result suites you, copy the working command and create a keyboard shortcut just as described in the link at the top of this answer.

Enjoy you new tweak!

Pizza
  • 1,428
  • See answer of BeastOfCaerbannog: there is a build-in keyboard shortcut to access the notifications. That answer also indicates how to customize that shortcut. – vanadium Mar 28 '21 at 16:17