(Solved) How to get the Number of the current desktop?

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
User avatar
LazY Puppy
Posts: 1934
Joined: Fri 21 Nov 2014, 18:14
Location: Germany

(Solved) How to get the Number of the current desktop?

#1 Post by LazY Puppy »

Hi.

I need to find out the number of the current/active desktop.

Any chance, to get it without to use xdotool or wmctrl?

Want to do this from within a bash script.

Thanks.
Last edited by LazY Puppy on Fri 18 Dec 2015, 07:54, edited 1 time in total.
RSH

"you only wanted to work your Puppies in German", "you are a separatist in that you want Germany to secede from Europe" (musher0) :lol:

No, but I gave my old drum kit away for free to a music store collecting instruments for refugees! :wink:

User avatar
rufwoof
Posts: 3690
Joined: Mon 24 Feb 2014, 17:47

#2 Post by rufwoof »

xprop -root _NET_CURRENT_DESKTOP|tail -c 3

provides the desktop number (starting from zero = desktop 1)

You might have to adjust that for desktops > 10 ???

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

Re: How to get the Number of the current desktop?

#3 Post by musher0 »

LazY Puppy wrote:Hi.

I need to find out the number of the current/active desktop.

Any chance, to get it without to use xdotool or wmctrl?

Want to do this from within a bash script.

Thanks.
Hi, Lazy.

You'll find a possible answer here.
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

User avatar
LazY Puppy
Posts: 1934
Joined: Fri 21 Nov 2014, 18:14
Location: Germany

#4 Post by LazY Puppy »

No, this wasn't successful.

A search at the page did not return any useful hints.

Tried to post a question as a guest, but the button didn't work for me. :cry:

However: thanks for the Link.
RSH

"you only wanted to work your Puppies in German", "you are a separatist in that you want Germany to secede from Europe" (musher0) :lol:

No, but I gave my old drum kit away for free to a music store collecting instruments for refugees! :wink:

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#5 Post by musher0 »

Code: Select all

xprop -root | awk '$1 ~ /CURRENT_DESK/ { print $NF }'
If zero you're on desktop 1; if one, you're on desktop 2; and so on.
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

User avatar
LazY Puppy
Posts: 1934
Joined: Fri 21 Nov 2014, 18:14
Location: Germany

#6 Post by LazY Puppy »

Yep, that's it!

Thanks! :D
RSH

"you only wanted to work your Puppies in German", "you are a separatist in that you want Germany to secede from Europe" (musher0) :lol:

No, but I gave my old drum kit away for free to a music store collecting instruments for refugees! :wink:

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#7 Post by musher0 »

Happy I did not help you! :twisted:
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#8 Post by MochiMoppel »

 
                              <removed>
 
 
Last edited by MochiMoppel on Sun 13 Dec 2015, 14:43, edited 1 time in total.

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#9 Post by musher0 »

Hello all.

I can't imagine why one would need more than 9 workspaces or desktops,
but these three bash lines will pad the first 9 desktop numbers with a "0".

Code: Select all

DESK="`xprop -root | awk '$1 ~ /CURRENT_DESK/ { print $NF }'`"
[ ${#DESK} -lt 10 ] && DESK="0$DESK"
echo $DESK
I'm sure someone can make that more concise, too. But essentially, that's
how padding is done before the number.

BFN.
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

User avatar
rufwoof
Posts: 3690
Joined: Mon 24 Feb 2014, 17:47

#10 Post by rufwoof »

musher0 wrote:I can't imagine why one would need more than 9 workspaces or desktops
I have a different puppypin for each desktop, so the icons/icon arrangements and wallpaper can all be different on each desktop. If you set the wallpaper to be a month calendar then you can position icons over particular dates - notes, to-do's... whatever. Or copies of work done (zip files etc) on particular days. 12 desktops.

For a busier individual perhaps 52 desktops (weekly calendar backgrounds).

Or you might have a desktop to reflect each of the main menu's 12 to 15 'sections'.

Or you might have 10+ remote PC's that you RemoteDesktop/VNC into, each running on their own desktop.

The limiting factor in other pup's is the same set of icons on each desktop. With that restriction lifted there's a wider range of possibilities.

some1
Posts: 117
Joined: Thu 17 Jan 2013, 11:07

#11 Post by some1 »

This is good rufwoof:
xprop -root _NET_CURRENT_DESKTOP|tail -c 3
provides the desktop number (starting from zero = desktop 1)
You might have to adjust that for desktops > 10 ???
Demonstrates that xprop has an inbuilt query-faclity

Probably the fastest to suck the output into a variable:

Code: Select all

NUM=$(xprop -root _NET_CURRENT_DESKTOP);NUM=${NUM##*' '}
echo $NUM
The above,and the next two wont have number-issues.

Code: Select all

time xprop -root _NET_CURRENT_DESKTOP|awk '$0=$NF'

Code: Select all

time xprop -root _NET_CURRENT_DESKTOP|cut -d ' ' -f3

Code: Select all

time xprop -root _NET_CURRENT_DESKTOP|tail -c 3
The 3 above have same runtime

This feeds all the xprop-stuff to awk - and is naturally the slowest.

Code: Select all

time xprop -root | awk '$1 ~ /CURRENT_DESK/ { print $NF }'

Edit: Typo '$0==$NF' corrected to '$0=$NF'

I guess USER wants the desktop-number as 1-based so:

Code: Select all

xprop -root _NET_CURRENT_DESKTOP|awk '$0=($NF+1)'

Code: Select all

NUM=$(xprop -root _NET_CURRENT_DESKTOP);NUM=$((${NUM##*' '}+1))
echo $NUM

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#12 Post by musher0 »

rufwoof wrote:
musher0 wrote:I can't imagine why one would need more than 9 workspaces or desktops
I have a different puppypin for each desktop, so the icons/icon arrangements and wallpaper can all be different on each desktop. If you set the wallpaper to be a month calendar then you can position icons over particular dates - notes, to-do's... whatever. Or copies of work done (zip files etc) on particular days. 12 desktops.

For a busier individual perhaps 52 desktops (weekly calendar backgrounds).

Or you might have a desktop to reflect each of the main menu's 12 to 15 'sections'.

Or you might have 10+ remote PC's that you RemoteDesktop/VNC into, each running on their own desktop.

The limiting factor in other pup's is the same set of icons on each desktop. With that restriction lifted there's a wider range of possibilities.
To each his own, man, to each his own! :)
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#13 Post by musher0 »

@some1:
Thanks for your "variations". :)

I like padding, though, in a case like this, and

Code: Select all

xprop -root _NET_CURRENT_DESKTOP|awk '{ print "0"($0=($NF+1)) }'
pads the number.

BFN.
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

amigo
Posts: 2629
Joined: Mon 02 Apr 2007, 06:52

#14 Post by amigo »

printf will pad numbers for you -but you'll have to consult the manual for how to do it -I'm only on my second coffee here...

some1
Posts: 117
Joined: Thu 17 Jan 2013, 11:07

#15 Post by some1 »

Musher0: RTMs as amigo suggests

Various printfs in the universe:
1.The shell printf -inbuilt or not.
2. awks printf - for formatting output
3 awks sprintf - for internal "printing" for usage inside awk - i.e.conversion,formatting.etc

Padded output:

Code: Select all

xprop -root _NET_CURRENT_DESKTOP|awk '{ printf "%02d",($NF+1);}'
---

RSH: step has a thing to show you,might help you handling the topless

Post Reply