SEARCH

Enter your search query in the box above ^, or use the forum search tool.

You are not logged in.

#1 2013-04-19 21:52:14

elias.ericson
Member
Registered: 2013-03-01
Posts: 18

Application keybinding with window toggle

Say you are working with specific applications alot and alt-tabs between them. Programs like chrome, geany, terminator etc. I noticed that sometimes it can take a few seconds to find chrome, or that specific terminal if you are running alot of programs at once. I found that wmctrl is a tool you can use for this purpose. I put together a little script that enables you to bind any program, e.g google-chrome terminator etc. It's a script that utilizes wmctrl. Use it with your favorite window manager e.g. openbox. When you press a key, just call this script and pass the executible as an argument.

Install

sudo apt-get install wmctrl
cd /usr/local/bin
sudo vim wswitch
#!/bin/bash
if [ "$(wmctrl -l -x | grep ${1^})" ]; then
	wmctrl -a $1 -x
else
	$1 &
fi
sudo chmod +x wswitch

Add keybindings in rc.xml (openbox)
Example keybindings:

<keybind key="section">
  <action name="Execute">
    <execute>wswitch terminator</execute>
  </action>
</keybind>

<keybind key="C-space">
  <action name="Execute">
    <execute>wswitch x-www-browser</execute>
  </action>
</keybind>
openbox --restart

If you don't have your browser opened it will start it.
If you have your browser already running it will focus
that window regardless where you are in the X-system.
Say you are working with terminator on desktop 4. If you
press C-space now you will automatically goto where
x-www-browser is at the moment and it will focus the window!

What do you think?

Edit: Rewrote subject/intro and switched from python to bash

Last edited by elias.ericson (2013-04-20 13:48:50)

Offline

Be excellent to each other!

#2 2013-04-20 09:25:52

xaos52
The Good Doctor
From: Planet of the @s
Registered: 2011-06-24
Posts: 4,602

Re: Application keybinding with window toggle

Its OK.
Only grudge I have is you use python to launch a couple of script commands.
Why don't you implement it in bash straight away, and not pay the penalty of starting python.

Offline

#3 2013-04-20 13:40:52

elias.ericson
Member
Registered: 2013-03-01
Posts: 18

Re: Application keybinding with window toggle

xaos52 wrote:

Its OK.
Only grudge I have is you use python to launch a couple of script commands.
Why don't you implement it in bash straight away, and not pay the penalty of starting python.

Yeah that's true, rewrote it in bash. Thanks for pointing it out.

Offline

Board footer

Powered by FluxBB

Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.

Debian Logo