Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Took me some time, but finally managed to get what you want (and eventually, what I also want :) with <code>xdotool</code> (on Ubuntu <code>sudo apt-get install xdotool</code>).</p> <p>With this script, you can have any application behave like you asked:</p> <pre><code>#!/bin/bash SEARCHED_WINDOW=$1 COMMAND=${2:-$SEARCHED_WINDOW} SEARCHED_WINDOW_CLASSNAME=toggleApp$SEARCHED_WINDOW WINDOW_ID=$(xdotool search --classname $SEARCHED_WINDOW_CLASSNAME) VISIBLE_WINDOW_ID=$(xdotool search --onlyvisible --classname $SEARCHED_WINDOW_CLASSNAME 2&gt;/dev/null) if [ -z "$WINDOW_ID" ]; then $COMMAND 2&gt;/dev/null &amp; pid=$! NEW_WINDOW_ID=$(xdotool search --onlyvisible --sync --pid $pid 2&gt;/dev/null) xdotool set_window --classname $SEARCHED_WINDOW_CLASSNAME $NEW_WINDOW_ID xdotool windowfocus $NEW_WINDOW_ID elif [ -z "$VISIBLE_WINDOW_ID" ]; then xdotool windowmap $WINDOW_ID xdotool windowfocus $WINDOW_ID else xdotool windowunmap $VISIBLE_WINDOW_ID fi </code></pre> <p>(Inspired from <a href="https://bbs.archlinux.org/viewtopic.php?id=71789&amp;p=1" rel="nofollow">here</a>)</p> <p>You call it like this:</p> <pre><code>./toggle.sh dolphin </code></pre> <p>If the command to launch the program is different, you can add a second parameter:</p> <pre><code>./toggle.sh appName commandToLaunchApp </code></pre> <p>What this script does is the following:</p> <ol> <li>If the app is not running: launch it, give window a specific class, and give window focus</li> <li>If the app is running but with no visible window: make window visible and give it focus</li> <li>Else, i.e. app is running and visible: hide it.</li> </ol> <p>All you have left to do is map a shortcut to the above-mentionned command to launch the script. In KDE : <em>System settings</em> > <em>Shortcuts and gestures</em> > <em>Custom shortcuts</em>. Then <em>Edit</em> > <em>New</em> > <em>Global shortcut</em> > <em>Command</em>.</p> <p>Plus, this script works with any app, should work with any <a href="http://en.wikipedia.org/wiki/Extended_Window_Manager_Hints" rel="nofollow" title="EWMH">EWMH</a> compliant window manager, and allows you to have other instances of the same app (this is why I added the class trick).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload