Kde shortcuts

I created shortcuts for Mousepad, Kcalc, Firefox and so on but there's something I just can't get working. When I enter the shortcut keys assigned to Mousepad it launches a new instance each time instead of opening an already minimized window of Mousepad.
Does anyone know how I can set it so that Mousepad launches a new instance only if it's not already running and opens the minimized Mousepad window when it is running?

Yes, this script will do it:

#!/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
#
#
# **IMPORTANT**
# 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="dolphin.dolphin"
LAUNCH_PROGRAM="/usr/bin/dolphin"
######################################################################################################
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

replace with correct values:
NEEDED_WINDOW_CLASS="dolphin.dolphin"
LAUNCH_PROGRAM="/usr/bin/dolphin"

1 Like

Thank you very much but how can I set that script to launch with a shortcut key?

Let me boot into KDE.......

Save to a file, make it executable, add to custom shortcuts:
image

Dolphin does launch but when the shortcut key is pressed again it still opens a new instance.

So what have you put in the command/url?

/home/francois/Desktop/Dolphin.sh

I did set it to executable in properties.

Have you got wmctrl + xdotool installed?

I had xdotool installed.
Now I installed wmctrl

Got it working!
Thanks!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.

Forum kindly sponsored by