4

I'm trying to add hotkeys to fast open some applications (for example KeePassXC) and I've done what I wanted

Keyboard Settings -> Keyboard Shortcuts -> /usr/bin/keepassxc ; wmctrl -a keepassxc

This works during the first run, or when the window was completely closed. The problem starts when the window is not activated and I want to activate it and bring to front. During pressing the hotkey Ubuntu just shows the notification that the Program is Ready, without activation. I'm new to the system, need help with finding the way to get rid of that notification and actually bring the needed app to the front with focus.

xiota
  • 4,849
0x49D1
  • 715

2 Answers2

4

You may use some GNOME shell extensions to remove the "Program is Ready" notification and also put the newly launched window into focus, for example

  1. 'Window Is Ready' Notification Remover
  2. NoAnnoyance (Removes the 'Windows is ready' notification and also puts the window into focus)
  3. Focus my window (same as above)
pomsky
  • 68,507
  • Great sample of answer: now I know about how to use GNOME extensions + "NoAnnoyance" was the thing I was looking for! And what's the logic behind that "Window is ready"? Thank you! – 0x49D1 May 07 '18 at 18:32
2

This may not do anything to resolve the notification issue in the question. However, the command pattern described ([cmd] ; wmctrl -a [cls]) may start multiple instances of a program, which the following script avoids. To use, save somewhere in the path, such as ~/bin/find_app.sh, and give it execute permission (chmod +x ~/bin/find_app.sh).

#! /usr/bin/env bash

if [ $# -lt 1 ]; then echo "usage: basename $0 [class-name] [command] [args]" echo echo "Find and activate window with [class-name]." echo "Execute [command] if window cannot be found." echo echo "If [command] is not given, it is assumed to be [class-name]" exit 1 fi

if [ $# -lt 2 ]; then

find_app="wmctrl -xa $class"

class="$1" find_app="xdotool search --onlyvisible --class $class windowactivate" command="$1" else class="$1" find_app="xdotool search --onlyvisible --class $class windowactivate" shift command="$@" fi

if (! eval "${find_app}") ; then eval "xdotool exec ${command}" fi

Note: xdotool may return an error for some apps:

XGetWindowProperty[_NET_WM_DESKTOP] failed (code=1)

A workaround for the issue is to add --desktop 0 to the find_app variables.

find_app="xdotool search --desktop 0 --onlyvisible --class $class windowactivate"
xiota
  • 4,849
  • 1
    This script works perfectly, thank you so much!! – Ethan Dec 27 '21 at 11:41
  • @Ethan Glad you found the script helpful. I recently learned that xdotool may return an error for some apps. In case you encounter it, I've added a description and workaround to the answer. – xiota Dec 30 '21 at 07:40