You are not logged in.

#1 2013-01-22 08:49:22

Rasi
Member
From: Germany
Registered: 2007-08-14
Posts: 1,914
Website

[SOLVED] help needed with active window script

I am trying to receive the current window from a script. it works fine, but when no window is open i get an error.

i am using this command:

xprop -id $(xprop -root 32x '\t$0' _NET_ACTIVE_WINDOW | cut -f 2) _NET_WM_NAME | cut -d '=' -f 2 | cut -b 1-2 --complement | rev | cut -c 2- | rev

error message is "Invalid Window id format: 0x0"

I tried working around this by using this script:

#!/bin/bash
title_window () { 
    xprop -id $(xprop -root 32x '\t$0' _NET_ACTIVE_WINDOW | cut -f 2) _NET_WM_NAME | cut -d '=' -f 2 | cut -b 1-2 --complement | rev | cut -c 2- | rev
}

title_root () {
    title_window | grep 0x0
}

if [[ -z title_root ]]
  then
    title_window
  else
    echo "Desktop"
fi

But now it shows "Desktop" for every window.

Last edited by Rasi (2013-01-22 11:59:46)


He hoped and prayed that there wasn't an afterlife. Then he realized there was a contradiction involved here and merely hoped that there wasn't an afterlife.

Douglas Adams

Offline

#2 2013-01-22 11:59:35

Rasi
Member
From: Germany
Registered: 2007-08-14
Posts: 1,914
Website

Re: [SOLVED] help needed with active window script

solved.

solution:

#!/bin/bash
title_window () { 
    xprop -id $(xprop -root 32x '\t$0' _NET_ACTIVE_WINDOW | cut -f 2) _NET_WM_NAME | cut -d '=' -f 2 | cut -b 1-2 --complement | rev | cut -c 2- | rev 2>&1
}

title_root () {
    title_window |& grep -q 0x0
}

if title_root;
  then
    echo "Desktop"
  else
   title_window
fi

He hoped and prayed that there wasn't an afterlife. Then he realized there was a contradiction involved here and merely hoped that there wasn't an afterlife.

Douglas Adams

Offline

Board footer

Powered by FluxBB