You are not logged in.

#1 2019-10-05 11:10:10

kes
Member
Registered: 2017-12-12
Posts: 21

Openbox: can I customise it to add a desktop with a specific name?

I am running the latest arch with Openbox and all the updates.

I currently have 4 Openbox desktops set up in rc.xml

I have just added this keybinding

<keybind key="W-F12">
  <action name="AddDesktop">
     <where>current</where>
  </action
</keybind>

When I press the `W-F12` key combo I get a new desktop called "desktop 5".

Anyone know if I can put a <name></name> tag somewhere in the above key binding to give it a specific relevant name?

Even better would be a script with a pop up box asking for new desktop name input.

eg  say i'm working on statistics and suddenly I want to create a desktop called "stats" how would I do that?   

reference: http://openbox.org/wiki/Help:Actions#AddDesktop

Last edited by kes (2019-10-05 11:12:50)

Offline

#2 2019-10-05 11:42:59

ohnonot
...again
Registered: 2015-09-29
Posts: 4,129
Website

Re: Openbox: can I customise it to add a desktop with a specific name?

Interesting.
I tried but it does not seem to be possible.
Also a desktop added via client-list-combined-menu (or your keybind) is not being added to rc.xml <desktops> section, it's kinda temporary, but the X session remembers it.
In other words, playing with it might require actually restarting X.org and not just openbox.
I have now tried to add more <names> than required, under <desktops>.
After restarting X I'd expect these names to be used when I "add a new desktop".

However, that doesn't answer your question - you want dynamic.
I'm pretty sure this is possible with a little script that
a) adds a new desktop
b) immediately names it with xprop

Offline

#3 2019-10-05 20:48:11

hhh
Meep!
Registered: 2015-09-17
Posts: 8,658
Website

Re: Openbox: can I customise it to add a desktop with a specific name?

You can edit desktop names in obconf (Main Menu>Preferences>Openbox>WM Preferences>Desktops>Desktop Names>double-click an entry and edit it>Close).

You could just add a fifth and sixth desktop and name them there (example: name Desktop 5 'Inkscape' and switch to it before opening Inkscape, or set an Inkscape shortcut keybind to open it on desktop 5, or use the Openbox window menu to send Inkscape to desktop 5 from the current desktop it's opened to). That will also alter the config file, maybe looking at that will help with a script.

Offline

#4 2019-10-06 11:41:46

brontosaurusrex
Middle Office
Registered: 2015-09-29
Posts: 1,909
Website

Re: Openbox: can I customise it to add a desktop with a specific name?

1. Playing around,

info

wmctrl -d
0  * DG: 3840x1200  VP: 0,0  WA: 6,42 3828x1112  first
1  - DG: 3840x1200  VP: 0,0  WA: 6,42 3828x1112  wasssuuuppp

backup

# backup first
cd .config/openbox
cp rc.xml rc.xml.bak

name

# name 1st desktop 'mkay'
xmlstarlet ed --inplace -N o="http://openbox.org/3.4/rc" \
-u '//o:openbox_config/o:desktops/o:names/o:name[1]' \
-v mkay rc.xml

refresh = problem

openbox --reconfigure # will not refresh names

However they do show in obconf.

edit: after some poking into obconf-2.0.4/src/desktops.c I think some sort of magic happens in line 214

    /* make openbox re-set the property */
    XDeleteProperty(GDK_DISPLAY(), GDK_ROOT_WINDOW(),
                    gdk_x11_get_xatom_by_name("_NET_DESKTOP_NAMES"));

but no clue what that means.

2. Workaround: Make shortkey to 'obconf --tab 6' so one lands directly in desktops section.

Last edited by brontosaurusrex (2019-10-06 19:39:25)

Offline

#5 2019-10-07 07:44:37

ohnonot
...again
Registered: 2015-09-29
Posts: 4,129
Website

Re: Openbox: can I customise it to add a desktop with a specific name?

^ always good for a quick & dirty one, eh? wink

Anyhow:

ohnonot wrote:

In other words, playing with it might require actually restarting X.org and not just openbox.
I have now tried to add more <names> than required, under <desktops>.
After restarting X I'd expect these names to be used when I "add a new desktop".

So that's in rc.xml, add more desktop names in the <desktop> <names> section, and more means: more than the <number> specified.
And indeed: only after restarting X, desktops added on-the-fly use these names.

But:

that doesn't answer your question - you want dynamic.
I'm pretty sure this is possible with a little script that
a) adds a new desktop
b) immediately names it with xprop

There's a ready-made python script in the first non-ad search result. It does the second half of what you want. You can call it from within a shell script that does the first part.

However, I still believe it's possible with xprop alone. If we only knew how.

Offline

#6 2019-10-07 07:58:38

brontosaurusrex
Middle Office
Registered: 2015-09-29
Posts: 1,909
Website

Re: Openbox: can I customise it to add a desktop with a specific name?

I tested that too, but not getting there (also that would not be permanent, which is ok in this case), possible 'xprop dformats' seems to be 8t, 8u and 8s.

xprop -root -f _NET_DESKTOP_NAMES 8u -set _NET_DESKTOP_NAMES 'woot, asaf' 

wmctrl -d                                                                
0  * DG: 1920x1200  VP: 0,0  WA: 6,46 1908x1108  woot, asaf
1  - DG: 1920x1200  VP: 0,0  WA: 6,46 1908x1108  two

xprop -root _NET_DESKTOP_NAMES 
_NET_DESKTOP_NAMES(UTF8_STRING) = "woot, asaf", "two"

I guess 8s could work, but not sure how to null-terminate string in shell.

https://superuser.com/questions/508128/ … ommandline

^ always good for a quick & dirty one, eh? wink

I might make that my blog title if it's ok. smile

Last edited by brontosaurusrex (2019-10-07 08:03:51)

Offline

#7 2019-10-07 08:35:03

ohnonot
...again
Registered: 2015-09-29
Posts: 4,129
Website

Re: Openbox: can I customise it to add a desktop with a specific name?

brontosaurusrex wrote:
xprop -root -f _NET_DESKTOP_NAMES 8u -set _NET_DESKTOP_NAMES 'woot, asaf' 

wmctrl -d                                                                
0  * DG: 1920x1200  VP: 0,0  WA: 6,46 1908x1108  woot, asaf
1  - DG: 1920x1200  VP: 0,0  WA: 6,46 1908x1108  two

xprop -root _NET_DESKTOP_NAMES 
_NET_DESKTOP_NAMES(UTF8_STRING) = "woot, asaf", "two"

That's what my experiments looked like, too.
Never managed to change all desktops names, only the first one. A "simple" formatting problem. sad
Tried 8u and 8s, not 8t though.

not sure how to null-terminate string in shell.

should be '\0', no?

I might make that my blog title if it's ok. smile

sure.

Offline

#8 2019-10-09 10:11:11

kes
Member
Registered: 2017-12-12
Posts: 21

Re: Openbox: can I customise it to add a desktop with a specific name?

I've done the following hack; it's messy but it works.
https://www.dropbox.com/sh/exdgtsgmu4qx … pR7ma?dl=0

to get it working you have to
- create a directory for the 3 files to sit in. The files are a png image, the bash script and the python script mentioned in the last post on this thread
- connect the file `set_desktop_name.sh` to a keybinding in your own rc.xml
- set the path variables at the top of the bash script
- install `yad` which should be in the repositories (https://sourceforge.net/projects/yad-dialog/)
- install `python-xpybutil` (the name this has on Arch which I'm on now), so that the python part of the script works

I used the quoted python script as I didn't want to go back and move that into bash until I got something working.

The latter part of the bash script changes the desktop names and uses sed to update  rc.xml to reflect the change. If your `rc.xml` file is formatted differently to mine you will need to make changes to this part of the script accordingly.     
 
No doubt someone who knows bash better than me can make the list like repeats more efficient using arrays/ lists and loops. My head does not have enough space to hold that kind of detail. I could dig it up, but this seems to work.

btw I have found that with named desktops I actually use desktops. I never used them before until I saw my friends daughter using them on her new apple the other day. I though "that's slick".
Before the last couple days I only ever used desktop "1".
2,3 & 4 just sat there.
Now they are all named and I have far more use of the laptop.
If like me you often have a few browsers open for different topics and never know which is which without clicking on them to see, then named work spaces is very very useful.
I have always found that clicking on each browser to see which is which distracts me and sets my head spinning.
I think dynamic naming of desktops is a break through !

Cheers

Last edited by kes (2019-10-09 16:14:50)

Offline

#9 2019-10-11 04:42:43

ohnonot
...again
Registered: 2015-09-29
Posts: 4,129
Website

Re: Openbox: can I customise it to add a desktop with a specific name?

kes wrote:

I think dynamic naming of desktops is a break through !

Great!
Personally I find tint2's approach (as seen on BL, but expanded to more desktops) usable enough - I can always see the icons of what sits on my other desktops, don't really need to name them.
But I know many people prefer to name desktops for a certain topic.

A little side-note:
Some people here don't (like to) use dropbox. Maybe the scripts are short enough to share directly?

Offline

#10 2019-10-19 13:41:55

kes
Member
Registered: 2017-12-12
Posts: 21

Re: Openbox: can I customise it to add a desktop with a specific name?

Here are the scripts requested in the previous post.

See my previous post for instructions on how to use.

I can't attach the image file as it isn't possible here it seems - but it is in the dropbox in my previous post, or just find and use your own. You will have to name this image file correctly as according to the script, and also check the path variables are also set correctly.

This hack could definateley use improvements. eg configure it to add desktops and remove them. That's for the future, or any one else who fancies a go.

Put the two following scripts, including an image, in a directory.
Seperate files for each of the two scripts.
Then call the shell script from a key binding. The shell/ bash script calls the python script.


Shell script. Save this as "set_desktop_name.sh"

#!/bin/bash



# check that correct dependancies are installed

# check that YAD is installed, if not install it
####package_z=yad
####str_z=$(echo $(pacman -Qi $package_z) | grep -oE $package_z | head -n 1); echo $str_z
####if [[ -z "$str_z" ]]; then 
####      echo $password_z | sudo -S pacman -S --noconfirm --needed $package_z
####fi

# check that `python-xpybutil` is installed, if not install it
####package_z=python-xpybutil
####str_z=$(echo $(pacman -Qi $package_z) | grep -oE $package_z | head -n 1); echo $str_z
####if [[ -z "$str_z" ]]; then 
####      echo $password_z | sudo -S pacman -S --noconfirm --needed $package_z
####fi


# set your own variables here
script_directory="/home/kes/Dropbox/00_PERS/linux_config/script_OPENBOX_set_desktop_name"
#rc_xml_file="/home/kes/.config/openbox/lubuntu-rc.xml"
rc_xml_file="/home/kes/Dropbox/lubuntu-rc.xml"



# set directory
cd $script_directory

# get existing desktop names list
##### desktop_list=$(echo "1|2|3|4")
desktop_list=$(xprop -root _NET_DESKTOP_NAMES |  grep -oE "\".*" | sed 's/, ""//g' | sed 's/", "/|/g' | sed 's/"//g')
echo $desktop_list


# yad pop up to display existing desktop list and collect new desktop name 
value_z=$(yad --geometry=400x100+512+384 \
--window-icon="desktop.png" \
--title="Change Desktop name" \
--text="" \
--image="desktop.png" \
--form \
--item-separator="|" \
--field="current desktop name":CBE \
--field="new desktop name" \
--button=gtk-cancel:0 --button=gtk-ok:0 \
"$desktop_list" "")

# if the yad dialogue was closed using esc key then no values have been received in the text input dialogue, in which case we should exit the script. The exit code for esc is "252".
exit_code="$?"
echo "the exit code for the yad dialogue is "$exit_code
if [[ "$exit_code" -eq "252" ]]; then 

   # indicate we found the exit code
   echo "252 exit code found. Escape key was pressed so we are going to exit"  

   # sleep for a bit so we can see if the exit code is working 
   #sleep 15

   # we are going to exit the script and do nothing if we get exit code 252, which is what the below line means
   exit 252
   
fi


# check that the two entries have been collected
echo
echo $value_z
echo


# extract variables from yad string
old_name=$(echo $value_z | awk 'BEGIN {FS="|" } { print $1 }')
new_name=$(echo $value_z | awk 'BEGIN {FS="|" } { print $2 }')

# check variables extracted correctly
echo $old_name
echo $new_name

# if new_name string is empty then new_name=$old name. This saves the system getting confused when no value is applied to "new_name"
if [ -z "$new_name" ]; then new_name=$old_name; fi
echo $new_name


# re-name the desktop
python set_desktop_name.py $(wmctrl -d | grep "$old_name"$ | grep -oE "^[0-9]{1}") "$new_name"



#####################   edit rc.xml dsktop entries to reflect changes ################################
 

# change the desktop naming part of openbox config file rc.xml, using sed
echo $desktop_list
a1_value=$(echo $desktop_list | awk 'BEGIN {FS="|" } { print $1 }')
a2_value=$(echo $desktop_list | awk 'BEGIN {FS="|" } { print $2 }')
a3_value=$(echo $desktop_list | awk 'BEGIN {FS="|" } { print $3 }')
a4_value=$(echo $desktop_list | awk 'BEGIN {FS="|" } { print $4 }')

#if you have nmore than 4 desktops, enable the below lines as appropriate
#### a5_value=$(echo $desktop_list | awk 'BEGIN {FS="|" } { print $5 }')
#### a6_value=$(echo $desktop_list | awk 'BEGIN {FS="|" } { print $6 }')
#### a7_value=$(echo $desktop_list | awk 'BEGIN {FS="|" } { print $7 }')
#### a8_value=$(echo $desktop_list | awk 'BEGIN {FS="|" } { print $8 }')

# check we have the old desktop names, so we know what to replace 
echo $old_name
echo $a1_value
echo $a2_value
echo $a3_value
echo $a4_value

# if you have more than 4 desktops, enable the below lines as appropriate
#### echo $a5_value
#### echo $a6_value
#### echo $a7_value
#### echo $a8_value


# find index number between 1 and 4 of value changed
if [[ "$old_name" == "$a1_value" ]]; then index_z=1; fi
if [[ "$old_name" == "$a2_value" ]]; then index_z=2; fi
if [[ "$old_name" == "$a3_value" ]]; then index_z=3; fi
if [[ "$old_name" == "$a4_value" ]]; then index_z=4; fi

# if you have more than 4 desktops, enable the below lines as appropriate
#### if [[ "$old_name" == "$a5_value" ]]; then index_z=5; fi
#### if [[ "$old_name" == "$a6_value" ]]; then index_z=6; fi
#### if [[ "$old_name" == "$a7_value" ]]; then index_z=7; fi
#### if [[ "$old_name" == "$a8_value" ]]; then index_z=8; fi

# check we have an index number for the change
echo $index_z


#>>>>>>>>>>>>>>>>>>>>>>>>>>>>  check for your own formatting of rc.xml here <<<<<<<<<<<<<<<<<<<<<

# our old desktop values in rc.xml
desktop_var="<name>"$a1_value"</name><name>"$a2_value"</name><name>"$a3_value"</name><name>"$a4_value"</name>"; echo $desktop_var

# our new desktop values in rc.xml
desktop_var_1="<name>"$new_name"</name><name>"$a2_value"</name><name>"$a3_value"</name><name>"$a4_value"</name>"; echo $desktop_var_1
desktop_var_2="<name>$a1_value</name><name>$new_name</name><name>$a3_value</name><name>$a4_value</name>"; echo $desktop_var_2
desktop_var_3="<name>$a1_value</name><name>$a2_value</name><name>$new_name</name><name>$a4_value</name>"; echo $desktop_var_3
desktop_var_4="<name>$a1_value</name><name>$a2_value</name><name>$a3_value</name><name>$new_name</name>"; echo $desktop_var_4

#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

# swap the values out the old value in rc.xml for the new value 
if [[ "$index_z" == "1" ]]; then sed -i "s|"$desktop_var"|"$desktop_var_1"|g" $rc_xml_file; fi
if [[ "$index_z" == "2" ]]; then sed -i "s|"$desktop_var"|"$desktop_var_2"|g" $rc_xml_file; fi
if [[ "$index_z" == "3" ]]; then sed -i "s|"$desktop_var"|"$desktop_var_3"|g" $rc_xml_file; fi
if [[ "$index_z" == "4" ]]; then sed -i "s|"$desktop_var"|"$desktop_var_4"|g" $rc_xml_file; fi


#¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬  working test ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
#rc_xml_file="/home/kes/.config/openbox/lubuntu-rc.xml";
#### rc_xml_file="/home/kes/Dropbox/lubuntu-rc.xml";
#### var1=general2;
#### var2=general22;
#### index_z=1; 
####  if [[ "$index_z" == "1" ]]; then echo "yes"; sed -i "s|<name>"$var1"</name>|<name>"$var2"</name>|g" $rc_xml_file; fi

#=================   working test ------------------
#### rc_xml_file="/home/kes/Dropbox/lubuntu-rc.xml"
#### index_z=1; 
#### a1_value=general
#### a2_value=browser
#### a3_value=docs
#### a4_value=stats
#### new_name=g2

#### if [[ "$index_z" == "1" ]]; then 
####    echo "yes"
####    sed -i "s|<name>"$a1_value"</name><name>"$a2_value"</name><name>"$a3_value"</name><name>"$a4_value"</name>|<name>"$new_name"</name><name>"$a2_value"</name><name>"$a3_value"</name><name>"$a4_value"</name>|g" $rc_xml_file; 
#### fi

#^^^^^^^^^^^^^^^^^   working test ^^^^^^^^^^^^^^^^^^
#### rc_xml_file="/home/kes/Dropbox/lubuntu-rc.xml"
#### index_z=1; 
#### a1_value=general
#### a2_value=browser
#### a3_value=docs
#### a4_value=stats
#### new_name=g2

#### desktop_var="<name>"$a1_value"</name><name>"$a2_value"</name><name>"$a3_value"</name><name>"$a4_value"</name>"
#### echo $desktop_var

#### desktop_var_1="<name>"$new_name"</name><name>"$a2_value"</name><name>"$a3_value"</name><name>"$a4_value"</name>"
#### echo $desktop_var_1

#### if [[ "$index_z" == "1" ]]; then sed -i "s|"$desktop_var"|"$desktop_var_1"|g" $rc_xml_file; fi

#¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬  working test ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
# index_z=2 ;old_name=1; a1_value=1; if [[ "$old_name" == "$a1_value" ]]; then index_z=1; fi; echo $index_z
# rc_xml_file="/home/kes/.config/openbox/lubuntu-rc.xml"; sed -i 's|<name>mower<\/name>|<name>m2<\/name>|g' $rc_xml_file

#¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬

Python script. Save this as "set_desktop_name.py"

#!/usr/bin/python2

#   reference 
#
#        https://superuser.com/questions/508128/is-it-possible-to-set-the-name-of-the-current-virtual-desktop-via-commandline
#
#      usage 
#           python set_desktop_name $(wmctrl -d | grep "old_desktop_name" | grep -oE "^[0-9]{1}") "new_desktop_name"
#


"Helper for setting current desktop's name"

import sys

from xpybutil import conn, root

import xpybutil.ewmh as ewmh

if len(sys.argv) == 2 and sys.argv[1] == '--help':
    print("Usage: ")
    print("set_desktop_name NAME_OF_NEW_DESKTOP  - sets current desktop name")
    print("set_desktop_name NR NAME_OF_NEW_DESKTOP- sets name of NRth desktop")

if len(sys.argv) > 2:
    desktop_offset = int(sys.argv[1])
    new_name = sys.argv[2]

else:
    desktop_offset = ewmh.get_current_desktop().reply()
    new_name = sys.argv[1]

current_names = ewmh.get_desktop_names().reply()

current_names[desktop_offset] = new_name

# Not sure why I have to do it twice - somehow
# doesn't work if I only call it once
c = ewmh.set_desktop_names(current_names)
c = ewmh.set_desktop_names(current_names) 

Last edited by kes (2019-10-19 13:48:28)

Offline

Board footer

Powered by FluxBB