Keyboard shortcuts to favorite applications (like in Windows and Gnome)

Gnome and Windows have that feature that makes accessing application windows very easy: when you have an application "pinned" in your application list, pressing super+1 takes you to the first pinned ap, super+2 to the second, etc.

The killer property of this feature for me is that when the pinned application is already open its window is brought to the front instead of opening a new window of the application.

This saved me a lot of time, because i didn't have to perform the mental effort of calculating how many times to press alt+tab, whether or not I have the app open, etc. Now I just say to the computer "Bring me to the app X" and that's where I'm brought to.

This is a feature that I really miss on XFCE. Obviously I could create an application shortcut to run firefox, but that would open a new Firefox window each time I press the key combination. Hardly useful.

So, I came up with a script of my own that does exactly that - I can bind it to whatever key combination my heart desires and make it run any app I want:

#!/bin/bash

CMD=$1
NOTIF_TIMEOUT=2000

if [ -n "$2" ]; then
    CLASS=$2
else
    CLASS=$CMD
fi

WINDOW_IDS=`xdotool search --class $CLASS` 

while read -r id; do
	if [[ $id = "" ]]; then
		break
	fi;
	info=`xwinfo -s $id`;
	if [[ $info != *"N/A"* ]]; then
                if [[ $info != *"modal"* ]]; then
			xdotool windowactivate $id;
			exit 0;
		fi
   	fi
	result=$id$' '$info;
done <<< "$WINDOW_IDS"


notify-send "Starting $CLASS..." -i "$CLASS" -t $NOTIF_TIMEOUT
echo $CMD
$CMD 


Use it like so:

$ ./raisewindow.sh firefox-developer-edition firefox

The first argument is the command to run, and the second is the app name. The script searches through windows with classnames matching the app name and brings it to focus.

I hope someone else finds it as useful as me :wink:

3 Likes

You can achieve the same thing by installing xfce4-dockbarx-plugin and adding it to one of your panels. The first ten pinned items can be raised by typing in super+number. This however is pretty cool for doing the same without a panel or plugin.

1 Like

Woah, very good to know!

What I like about my solution is that I can have more than 10 shortcuts - as I can bind it to super+<letter> as well :wink:

1 Like

This is my version of the same thing :smiley:

#!/bin/bash
######################################################################################################
# This script will toggle minimize/activate first window with specified class
# If window not found program will be launched
#
# window class can be found with next programs:
#   wmctrl -x -l
#   xprop
# No credit taken.......... Cannot read the original.....
# Found on http://blog.sokolov.me/2014/06/20/linuxx11-toggle-window-minimizemaximize/
# in Russian :) but works when adjusting the wrapping.
# Assigned to meta-f in KDE plasma 5
######################################################################################################
NEEDED_WINDOW_CLASS="Navigator.Nightly"
LAUNCH_PROGRAM="firefox-nightly" 
######################################################################################################
NEEDED_WINDOW_WINDOW_ID_HEX=`wmctrl -x -l | grep ${NEEDED_WINDOW_CLASS} | awk '{print $1}' | head -n 1`
NEEDED_WINDOW_WINDOW_ID_DEC=$((${NEEDED_WINDOW_WINDOW_ID_HEX}))
if [ -z "${NEEDED_WINDOW_WINDOW_ID_HEX}" ]; then
    ${LAUNCH_PROGRAM}
else
    echo "Found window ID:${NEEDED_WINDOW_WINDOW_ID_DEC}(0x${NEEDED_WINDOW_WINDOW_ID_HEX})"
    ACIVE_WINDOW_DEC=`xdotool getactivewindow`
    if [ "${ACIVE_WINDOW_DEC}" == "${NEEDED_WINDOW_WINDOW_ID_DEC}" ]; then
        xdotool windowminimize ${NEEDED_WINDOW_WINDOW_ID_DEC}
    else
        xdotool windowactivate ${NEEDED_WINDOW_WINDOW_ID_DEC}
    fi
fi

Just thought I would share :wink:

4 Likes

Forum kindly sponsored by