topic title: Application Focus
Posts: 316
DJiNN
Joined: 26 Oct 2007
#1
All credit for this goes to
========= SCRAPER REMOVED AN EMBEDDED LINK HERE ===========
url was:"http://urukrama.wordpress.com/"
linktext was:"Urukrama"
====================================
. All that i have done is altered a few names in the original scripts to make them work with the apps i use. __{{emoticon}}__

For the sake of brevity,
========= SCRAPER REMOVED AN EMBEDDED LINK HERE ===========
url was:"http://urukrama.wordpress.com/2008/05/05/focus-an-application-instead-of-re-launching-it/"
linktext was:"THIS"
====================================
will explain what these scripts do and what "Application Focus" is all about. Once you've read it (it's only a few paragraphs) then you should know what the following scripts are and how to use them.

The original scripts are for Thunar & Terminal (gnome?) but i tend to use XFCE4-Term, RoxTerm, Thunar & PCmanFM, so i've modified the scripts to work with those apps. I've included the script for each app below. All you need to do is save each one to it's own file & call it whatever you like. I have prefixed all of mine with a"1" (ie: 1roxterm.sh - 1thunar.sh etc) and made the script file executable. Then it's just a case of adding the relevant code to the fluxbox menu like so:

Code: Select all

         [exec] (1-PCmanFM) {~/.1pcmanfm.sh}
     [exec] (1-XFCE4-Term) {~/.1xfce4term.sh}
     [exec] (1-Thunar) {~/.1thunar.sh}
     [exec] (1-RoxTerm) {~/.1roxterm.sh}
and that's it. Now whenever you click on, say"PCmanFM" for instance, whatever desktop you happen to be on, PCmanFM will appear on THAT desktop, and it will always be available whatever desktop you're on. As you can imagine, this is really helpful on systems with a low amount of RAM. __{{emoticon}}__

So here are the scripts:

FOR THUNAR:

Code: Select all

#!/bin/sh

thunar_wm_class="thunar"
thunar_exec="thunar"

# no thunar started, so start one
if [ -z"`wmctrl -lx | grep thunar`" ]; then
    $thunar_exec &
else
    # search for existing thunars on current desktop
    current_desk=`wmctrl -d | grep '*' | cut -d ' ' -f 1`
    thunar_on_this_desk=`wmctrl -lx | grep"$current_desk[ ]*$thunar_wm_class" | cut -d ' ' -f 1`
    if [ -n"$thunar_on_this_desk" ]; then
        wmctrl -i -a $thunar_on_this_desk
    else
        # no thunars on current desktop, so open a new one
        wmctrl -x -R $thunar_wm_class
    fi;
fi;
FOR PCMANFM:

Code: Select all

#!/bin/sh

pcmanfm_wm_class="pcmanfm"
pcmanfm_exec="pcmanfm"

# no pcmanfm started, so start one
if [ -z"`wmctrl -lx | grep pcmanfm`" ]; then
    $pcmanfm_exec &
else
    # search for existing pcmanfm on current desktop
    current_desk=`wmctrl -d | grep '*' | cut -d ' ' -f 1`
    pcmanfm_on_this_desk=`wmctrl -lx | grep"$current_desk[ ]*$pcmanfm_wm_class" | cut -d ' ' -f 1`
    if [ -n"$pcmanfm_on_this_desk" ]; then
        wmctrl -i -a $pcmanfm_on_this_desk
    else
        # no pcmanfm's on current desktop, so open a new one
        wmctrl -x -R $pcmanfm_wm_class
    fi;
fi;
FOR ROXTERM:

Code: Select all

#!/bin/sh

terminal_wm_class="roxterm"
terminal_exec="roxterm"

# no terminal started, so start one
if [ -z"`wmctrl -lx | grep roxterm`" ]; then
    $terminal_exec &
else
    # search for existing terminals on current desktop
    current_desk=`wmctrl -d | grep '*' | cut -d ' ' -f 1`
    term_on_this_desk=`wmctrl -lx | grep"$current_desk[ ]*$terminal_wm_class" | cut -d ' ' -f 1`
    if [ -n"$term_on_this_desk" ]; then
        wmctrl -i -a $term_on_this_desk
    else
        # no terminals on current desktop, so just open a new one
        wmctrl -x -R $terminal_wm_class
    fi;
fi;
FOR XFCE4-TERM:

Code: Select all

#!/bin/sh

terminal_wm_class="Terminal"
terminal_exec="xfce4-terminal"

# no terminal started, so start one
if [ -z"`wmctrl -lx | grep terminal`" ]; then
    $terminal_exec &
else
    # search for existing terminals on current desktop
    current_desk=`wmctrl -d | grep '*' | cut -d ' ' -f 1`
    term_on_this_desk=`wmctrl -lx | grep"$current_desk[ ]*$terminal_wm_class" | cut -d ' ' -f 1`
    if [ -n"$term_on_this_desk" ]; then
        wmctrl -i -a $term_on_this_desk
    else
        # no terminals on current desktop, so just open a new one
        wmctrl -x -R $terminal_wm_class
    fi;
fi;
I have tested all of these & they work just fine and have made a big difference to my system and the way that i work.

Enjoy. __{{emoticon}}__
anticapitalista
Posts: 5,955
Site Admin
Joined: 11 Sep 2007
#2
Nice tip DJiNN.

Does it work with rox-filer rather than thunar or pcmanfm?

OK, yes it does. Here is the script.

Code: Select all

#!/bin/sh

rox_wm_class="rox"
rox_exec="rox"

# no rox started, so start one
if [ -z"`wmctrl -lx | grep rox`" ]; then
    $rox_exec &
else
    # search for existing rox on current desktop
    current_desk=`wmctrl -d | grep '*' | cut -d ' ' -f 1`
    rox_on_this_desk=`wmctrl -lx | grep"$current_desk[ ]*$rox_wm_class" | cut -d ' ' -f 1`
    if [ -n"$rox_on_this_desk" ]; then
        wmctrl -i -a $rox_on_this_desk
    else
        # no rox on current desktop, so open a new one
        wmctrl -x -R $rox_wm_class
    fi;
fi;
In some ways it might be even better to open the script via hotkey (fluxbox/keys) rather than through the fluxbox menu.
eg
Mod1 h :ExecCommand ./rox.sh
Posts: 316
DJiNN
Joined: 26 Oct 2007
#3
Thanks anti. __{{emoticon}}__

I would imagine that it would work with most things, which is really cool. On Urukrama's blog he does go on to say about using key bindings with the scripts. Unfortunately, i just can't get the MOD4 key to work in fluxbox on any of my machines. When ever i press the MOD4 key (Win Key?) with another key that, according to the keys file, should trigger something, nothing happens.

Hmmm, just tried it, and actually some of them do work. MOD1 (The Alt key?) does seem to work, so something like MOD1 TAB will flip between windows (Apps) etc. It seems to be ONLY the MOD4 key that's NOT recognised.

But yeah, the scripts are great, and i shall add that Rox one to my list. __{{emoticon}}__
Posts: 316
DJiNN
Joined: 26 Oct 2007
#4
Stranger still, i just added your script for Rox Filer to a MOD1 F5 keybinding, but everytime i press it, it just brings up Roxterm instead! LOL!! How odd is that? All the other scripts work fine though.
anticapitalista
Posts: 5,955
Site Admin
Joined: 11 Sep 2007
#5
Hmm, sure you've got the name of the script file right?
Posts: 316
DJiNN
Joined: 26 Oct 2007
#6
I think so. I've checked every letter, and checked whether it's executable etc, and everything seems to be OK. I'll get to the bottom of it eventually. __{{emoticon}}__

One thing you could help me with though, is the location of the xmodmap.conf file. I thought it was in /etc but it doesn't seem to be anywhere on the system. Yet when i do an xmodmap -pm it brings up the settings etc, of which there are NONE for the MOD4 key, that's why i want to add it into the xmodmap.conf, or should i be looking for another file?
anticapitalista
Posts: 5,955
Site Admin
Joined: 11 Sep 2007
#7
I think it should be .xmodmaprc and placed in your home directory.
There isn't one by default in antiX.


========= SCRAPER REMOVED AN EMBEDDED LINK HERE ===========
url was:"http://lassauge.free.fr/cygwin/.xmodmaprc"
linktext was:"http://lassauge.free.fr/cygwin/.xmodmaprc"
====================================
Posts: 316
DJiNN
Joined: 26 Oct 2007
#8
That's great. Thanks for that anti. __{{emoticon}}__