Xfce Forum

Sub domains
 

You are not logged in.

#1 2022-11-22 07:25:04

Skaperen
Member
From: right by Jesus, our Saviour
Registered: 2013-06-15
Posts: 812

get the current workspace number

the panel (work space switcher plug-in) is able to know what the current workspace number is.  is that because it is actually doing the work of keeping track of it when it changes?

what i want to do is have my script find out the current workspace number reliably even if that workspace currently has no windows open, e.g. "wmctrl -l" output, which i have been using to discover the current workspace by assuming the the script is in the current workspace and looking for the pid of xfce4-terminal the script is running under (i find out the term pid by chasing parent process ids back as gotten from "ps -ef").

the assumptions have changed.  i now need to run this script away from the current workspace.  it needs to know what the current workspace being displayed is, even though it is not running there.

Last edited by Skaperen (2022-11-22 07:25:34)

Offline

#2 2022-11-22 11:38:08

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 10,949

Re: get the current workspace number

Skaperen wrote:

the panel (work space switcher plug-in) is able to know what the current workspace number is.  is that because it is actually doing the work of keeping track of it when it changes?

It uses/relies on libwnck to give it this information

it needs to know what the current workspace being displayed is, even though it is not running there.


You can get the current workspace with "wmctrl -d" - it will have an "*" in the second column, or:

wmctrl -d | grep \* | awk '{print $1}'

...where workspace numbering starts at 0.


Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#3 2022-11-22 18:01:56

Skaperen
Member
From: right by Jesus, our Saviour
Registered: 2013-06-15
Posts: 812

Re: get the current workspace number

@ToZ Thanks!

Offline

#4 2022-11-22 18:53:37

Skaperen
Member
From: right by Jesus, our Saviour
Registered: 2013-06-15
Posts: 812

Re: get the current workspace number

in case anyone wants a script to use that command and get the current workspace, such as for other scripts, i wrote a little one in python:

#!/usr/bin/env python3
from subprocess import PIPE,Popen
with Popen(['wmctrl','-d'],stdout=PIPE,universal_newlines=True) as proc:
    for o in proc.stdout.read().splitlines():
        p = o.split()
        if len(p) < 3:continue
        w,f = p[:2]
        if f == "*":print(w)

name it anything you want.  i named mine "currws".

Offline

Board footer

Powered by FluxBB