[openbox] Go to a program if it's already running

Wujek Srujek wujek.srujek at gmail.com
Thu Jul 18 13:43:24 EDT 2013


I was wandering the same thing about 2 months ago, and I came up with the
following script based on Ukurama's thoughts:

raise:

!/usr/bin/bash

if [ "$#" -gt 1 ]; then
    echo "Has arguments, starting..."
    "$@" &
    exit
fi

CMD="$1"
app="$(wmctrl -lx | grep "$CMD" | head -n 1)"
if [ -z "$app" ]; then
    echo "App not found, starting..."
    "$CMD" &
else
    id="$(echo $app | cut -f 1 -d ' ')"
    echo "Refocusing app..."
    wmctrl -i -R "$id"
fi

You use it like:
raise lxterminal # will start the first terminal
raise lxterminal # will refocus to the previously running instance

I then used raise in all my openbox keyboard shortcuts, and it works, most
of the time. Some apps might not, for example java swing apps because the
script relies on application names, and some of them are just called java.
Also, if it finds multiple application instances it refocuses only the
first one listed by wmctrl, and I don't know how they are sorted. But you
might still find it useful as I have.

wujek


On Thu, Jul 18, 2013 at 7:23 PM, Brian Mattern <rephorm at rephorm.com> wrote:

> There was a thread in Oct. 2011 titled "Launching applications" that
> gives various examples of accomplishing this for one specific program
> (mutt launched in a terminal).
>
> I'm not sure you could generalize the method easily, however.
>
> Brian
>
> On Thu, 18 Jul 2013, Antoine wrote:
>
> > Hello!
> > I've been an Openbox user for a while now, and it is the best
> > interface known to man.
> > However, there's something I never managed to do :
> > Imagine you have an item in the root menu corresponding to an
> > application. If the application has not been launched yet, then run
> > it.
> > But if the application is already running, just go to the workspace
> > where the window is, and raise the window.
> > In an ideal world, if there are more than one window, display a
> > submenu allowing to choose the wanted one.
> > You'll notice that it's the habitual behavior of most "docks", like
> > in Unity or even Windows. But it would be awesome to be able to do
> > it with Openbox menus.
> > Is there currently some hackish way to do this? I believe it would
> > be a very useful feature otherwise.
> >
> > Cheers,
> > Antoine from France
> > _______________________________________________
> > openbox mailing list
> > openbox at icculus.org
> > http://icculus.org/mailman/listinfo/openbox
> _______________________________________________
> openbox mailing list
> openbox at icculus.org
> http://icculus.org/mailman/listinfo/openbox
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://icculus.org/pipermail/openbox/attachments/20130718/832b3c0d/attachment.html>


More information about the openbox mailing list