You are not logged in.

#1 2021-05-14 09:01:07

lbdesign
Member
Registered: 2018-05-13
Posts: 25

Change openbox theme from terminal?

I have made scripts to change gtk-theme, icon-theme and switch out configs for tint2, xfce4-terminal and more. The only thing I need is a script to change openbox theme then I can change all appearance with a string of scripts from the terminal as an alias, but can't find the commands I need for changing ob theme.

Example from my gtkswitch script

#!/bin/sh
# Displays a list of files in current directory and prompt for which
# file to edit

# Set the prompt for the select command
PS3="Type a number or 'q' to quit: "

# Create a list of files to display
fileList=$(cat $(find ~/.themes -name index.theme) | grep "Name=" | cut -d "=" -f2 | sort -n)

# Show a menu and ask for input. If the user entered a valid choice,
# then invoke the editor on that file
select fileName in $fileList; do
    if [ -n "$fileName" ]; then
        sed -i "s/.*gtk-theme-name=.*/gtk-theme-name=${fileName}/g" ~/.config/gtk-3.0/settings.ini
        sed -i "s/.*gtk-theme-name=.*/gtk-theme-name=${fileName}/g" ~/.gtkrc-2.0
    fi
    break
done

the other scripts are in the same style so nothing fancy but, yeah, just need the last script to change openbox theme. Here is another example for tint2

#!/bin/sh
# Displays a list of files in current directory and prompt for which
# file to edit

# Set the prompt for the select command
PS3="Type a number or 'q' to quit: "

# Create a list of files to display
fileList=$(find ~/.config/tint2 -name *tint2rc -type f)

# Show a menu and ask for input. If the user entered a valid choice,
# then invoke the editor on that file
select fileName in $fileList; do
    if [ -n "$fileName" ]; then
	cp ${fileName} ~/.config/tint2/tint2rc
	fi
    break
done

killall tint2
tint2 &

Last edited by lbdesign (2021-05-14 09:03:50)

Offline

#2 2021-05-14 09:29:16

damo
....moderator....
Registered: 2015-08-20
Posts: 6,619

Re: Change openbox theme from terminal?

BL has the inbuilt BLOB themes manager to do all of those things. If you want to see how we accomplish what you want, then have a look at /usr/bin/bl-obthemes. The functions for changing the Openbox themes are

function getOBtheme()
function getOBname()
function restoreOBrc()

You should find something useful for your scripts in there smile


Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#3 2021-05-14 09:42:34

lbdesign
Member
Registered: 2018-05-13
Posts: 25

Re: Change openbox theme from terminal?

Thanks. I'm not a coder (this is as advanced I have ever done) but I'll see what I can find.

Offline

#4 2021-05-14 09:48:12

damo
....moderator....
Registered: 2015-08-20
Posts: 6,619

Re: Change openbox theme from terminal?

Basically it is using sed to find and replace the theme name in bl-rc.xml, then running

openbox --reconfigure

Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#5 2021-05-14 10:58:52

lbdesign
Member
Registered: 2018-05-13
Posts: 25

Re: Change openbox theme from terminal?

Here is the finished script so far. Still more to do but it works good enough for now.

#!/bin/sh

# switch gtk theme
clear
echo -e "Choose gtk theme \n"
PS3="Type a number or 'q' to quit: "
fileList=$(find ~/.themes -maxdepth 1 -type d | grep -v "ob-*" | cut -d "/" -f5 | sort -n)

select fileName in $fileList; do
    if [ -n "$fileName" ]; then
        sed -i "s/.*gtk-theme-name=.*/gtk-theme-name=${fileName}/g" ~/.config/gtk-3.0/settings.ini
        sed -i "s/.*gtk-theme-name=.*/gtk-theme-name=${fileName}/g" ~/.gtkrc-2.0
    fi
    break
done

# switch icon theme
clear
echo -e "Choose icon theme \n"
PS3="Type a number or 'q' to quit: "
fileList=$(find ~/.icons -maxdepth 1 -type d  | cut -d "/" -f5 | sort -n)

select fileName in $fileList; do
    if [ -n "$fileName" ]; then
        sed -i "s/.*gtk-icon-theme-name=.*/gtk-icon-theme-name=${fileName}/g" ~/.config/gtk-3.0/settings.ini
        sed -i "s/.*gtk-icon-theme-name=.*/gtk-icon-theme-name=${fileName}/g" ~/.gtkrc-2.0
    fi
    break
done

# switch openbox theme
clear
echo -e "Choose openbox theme \n"
PS3="Type a number or 'q' to quit: "
fileList=$(find ~/.themes -type d -name "openbox-3"  | cut -d "/" -f5)

select fileName in $fileList; do
    if [ -n "$fileName" ]; then
    sed -i "s/$(grep "<theme>" ~/.config/openbox/rc.xml -A 5 | grep "<name>"| awk -F"[><]" '{print $3}')/$fileName/g" ~/.config/openbox/rc.xml
    openbox --reconfigure
    fi
    break
done

# switch xfce4-terminal config
clear
echo -e "Choose xfce4-terminal config \n"
PS3="Type a number or 'q' to quit: "
fileList=$(find ~/.config/xfce4/terminal -name *terminalrc* -type f)

select fileName in $fileList; do
    if [ -n "$fileName" ]; then
	cp ${fileName} ~/.config/xfce4/terminal/terminalrc
	fi
    break
done

# switch tint2 config
clear
echo -e "Choose tint2 config \n"
PS3="Type a number or 'q' to quit: "
fileList=$(find ~/.config/tint2 -name *tint2rc -type f)

select fileName in $fileList; do
    if [ -n "$fileName" ]; then
	cp ${fileName} ~/.config/tint2/tint2rc
	fi
    break
done

openbox --exit

be aware of the last line if you run it smile

Last edited by lbdesign (2021-05-14 13:43:48)

Offline

#6 2021-05-15 06:36:31

brontosaurusrex
Middle Office
Registered: 2015-09-29
Posts: 2,318
Website

Re: Change openbox theme from terminal?

Just a general remark, when dealing with small files like this config stuff, I tend to use the -b switch with cp, just in case.

cp -b src dst

which should do a backup of dst named dst~.

edit: Also maybe interesting, https://forums.bunsenlabs.org/viewtopic.php?id=5075

Last edited by brontosaurusrex (2021-05-15 20:17:40)

Offline

#7 2021-05-16 16:45:23

ohnonot
...again
Registered: 2015-09-29
Posts: 5,482

Re: Change openbox theme from terminal?

lbdesign, I do it like this:

cp -f "$ob_rc" "$ob_rc"."$me"
# priceless piece of information: https://superuser.com/a/508143
xmlstarlet ed -L -N o="http://openbox.org/3.4/rc" -u '/o:openbox_config/o:theme/o:name' -v "$CURRENT_THEME" "$ob_rc"

xmlstarlet is a more suitable tool for editing XML files.


Give to COVAX! Here or here. (explanation)

Offline

#8 2021-05-17 08:47:58

lbdesign
Member
Registered: 2018-05-13
Posts: 25

Re: Change openbox theme from terminal?

brontosaurusrex wrote:

Just a general remark, when dealing with small files like this config stuff, I tend to use the -b switch with cp, just in case.

I only use the cp command to copy from a number of configs in a folder to the one loaded by the program, tint2 and xfce4-terminal in this case, so there are already backups.

brontosaurusrex wrote:

Looks good. I'll have a look at the github for tips and hints. I wanted a script where I chose each config so I can mix and match, say sometimes I want a dark terminal and tint2 but light gtk and ob themes on rainy days but everything light on sunny days,


ohnonot wrote:

lbdesign, I do it like this:

cp -f "$ob_rc" "$ob_rc"."$me"
# priceless piece of information: https://superuser.com/a/508143
xmlstarlet ed -L -N o="http://openbox.org/3.4/rc" -u '/o:openbox_config/o:theme/o:name' -v "$CURRENT_THEME" "$ob_rc"

xmlstarlet is a more suitable tool for editing XML files.

I understand nothing of that. Not a coder here. Isn't $ob_rc a variable? And where do I set that?

Last edited by lbdesign (2021-05-17 08:48:34)

Offline

#9 2021-05-17 08:55:44

brontosaurusrex
Middle Office
Registered: 2015-09-29
Posts: 2,318
Website

Re: Change openbox theme from terminal?

lbdesign wrote:
brontosaurusrex wrote:

Looks good. I'll have a look at the github for tips and hints. I wanted a script where I chose each config so I can mix and match, say sometimes I want a dark terminal and tint2 but light gtk and ob themes on rainy days but everything light on sunny days,

I see, my lil script works similar to it's influencer (blob), storing everything (whatever is preconfigured in script) in slots. What I find interesting is that it can compare active vs stored configs with some diff-ing around. That same diff will also prevent storing exactly the same slot that already exist.  p.s. Also keep in mind that it is not compatible with bunsen paths, targeting plain Debian openbox.

Offline

#10 2021-05-17 09:03:11

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 8,003
Website

Re: Change openbox theme from terminal?

@lbdesign it looks to me as if the existing BLOB script shipped with BunsenLabs might do what you want.

Menu > BL Utilities > BLOB Themes Manager

Set up your themes, settings etc the way you want it for eg RainyDay, then use BLOB to save the settings with a name you choose. Do the same for SunnyDay etc... You can then use BLOB to restore whichever setup you want.

BLOB is meant to be usable that way, so if it doesn't work for you we'd be interested to know! smile


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), idle Twitterings and GitStuff )

Introduction to the Bunsenlabs Lithium Desktop

Offline

#11 2021-05-17 10:04:39

lbdesign
Member
Registered: 2018-05-13
Posts: 25

Re: Change openbox theme from terminal?

I don't use bunsenlabs anymore, but have a minimal debian netinstall with openbox. Also I want the script to be simple and usable on whatever distro I use. It's a highly personal project meant to be used by me only smile

Offline

#12 2021-05-18 02:43:53

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 8,003
Website

Re: Change openbox theme from terminal?

^OK understood. It sounds like a nice project.

After spending some time on BLOB (with @damo) I think it's safe to say it won't necessarily turn out to be so simple!
But the code might give you some ideas - it's in /usr/bin/bl-obthemes (~2000 lines atm), or here: https://github.com/BunsenLabs/bunsen-ut … l-obthemes

Maybe @brontosaurusrex's script will be a better base...


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), idle Twitterings and GitStuff )

Introduction to the Bunsenlabs Lithium Desktop

Offline

#13 2021-05-18 05:49:37

ohnonot
...again
Registered: 2015-09-29
Posts: 5,482

Re: Change openbox theme from terminal?

lbdesign wrote:

I understand nothing of that. Not a coder here. Isn't $ob_rc a variable? And where do I set that?

Oh, I'm sorry.
ob_rc is a variable that contains the path to your openbox rc.xml.
The first line is just making a backup; let's remove it to make it a little clearer, hopefully.
Let's assume you want to change the current theme to Adwaita:

theme="Adwaita"
ob_rc="$HOME/.config/openbox/rc.xml"
# priceless piece of information: https://superuser.com/a/508143
xmlstarlet ed -L -N o="http://openbox.org/3.4/rc" -u '/o:openbox_config/o:theme/o:name' -v "$theme" "$ob_rc"

XML is best edited with XML tools, of which there are plenty.
openbox generates XML with newlines between nodes, and always has; it is probably pretty safe to edit it with sed, which is a line editor.
But XML per se does not require newlines at all, and in a case like that sed would probably fail.


Give to COVAX! Here or here. (explanation)

Offline

#14 2021-05-18 11:02:12

lbdesign
Member
Registered: 2018-05-13
Posts: 25

Re: Change openbox theme from terminal?

Yeah. I can see I stand at the edge of a rabbit hole smile I might just stick with lxappearance for gtk and icon stuff since some programs, like gpick, doesn't obey the changes to settings.ini and .gtkrc files. All I wanted to do was make life a little easier smile

I installed xmlstarlet and got it working and it's brilliant. Going to make working with xml files so much easier in the future. Thanks for the tip.

# switch openbox theme
clear
echo -e "Choose openbox theme \n"
PS3="Type a number or 'q' to quit: "
fileList=$(find ~/.themes -type d -name "openbox-3"  | cut -d "/" -f5)
ob_rc="$HOME/.config/openbox/rc.xml"

select fileName in $fileList; do
    if [ -n "$fileName" ]; then
    # priceless piece of information: https://superuser.com/a/508143
    xmlstarlet ed -L -N o="http://openbox.org/3.4/rc" -u '/o:openbox_config/o:theme/o:name' -v "$fileName" "$ob_rc"
    openbox --reconfigure
    fi
    break
done

Offline

Board footer

Powered by FluxBB