You are not logged in.

#1 2015-03-25 19:01:18

ChrisODonnell
Member
Registered: 2010-03-06
Posts: 8

Unity-style application swapping in openbox

I missed the W-1 binding in unity, which launches an application if it's not already running or changes focus to it if it is already running, so I decided to implement the feature in openbox.

I wrote a bash script launch_or_swap, which is pretty simple:

#!/bin/bash

if wmctrl -lx | grep -i --quiet "$1"; then
	wmctrl -x -a "$1"
else
	"$1" &
fi

It uses wmctrl with the -x parameter to list the currently open windows, including their WM_CLASS. This list is piped to grep, which searches for the name of the application we are looking to access. For the three applications I am using this for (terminator, firefox, and evince), the application binary name is included in WM_CLASS. I don't know if this is always the case; YMMV. If an appropriate application window is found, wmctrl swaps to it. Otherwise, the application is launched.

To create the W-1 hotkey for terminator I added this to ~/.config/openbox/rc.xml:

<keybind key="W-1">
	<action name="Execute">
		<command>launch_or_swap terminator</command>
	</action>
</keybind>

If anyone has suggestions for better ways to accomplish this or improvements, I'd be happy to hear them.

Last edited by ChrisODonnell (2015-03-25 19:01:42)

Offline

Board footer

Powered by FluxBB