You are not logged in.
I am trying create a script to toggle between two themes independent of the currently active theme.
So basically, regardless of what theme is active, switch to "Glacier", a light theme, and then toggle to "Anolis" on second press, and back and forth. The idea is that when confronted by some dark theme anomoly, or any other reason, you can switch to a decent light theme on a button press or keybind. Easy enough to just set two keybinds but better to have a script.
Ideally, the script would grab the currently activated theme regardless, and switch back to that on return toggle, but that version is beyond me, where the first idea seems quite doable. (I would most gladly use the second version though!)
Anyway, the below is obviously not correct but may jog something easy for someone. My guess is I don't even need $FILE and $STRING as the changes (for my first option) don't care what is currently active . . . but how do you then take care of the back and forth after the initial press? Yeah, I'm lost here. 8o
#!/bin/bash
#
FILE="$HOME/.config/xfce4/xfconf/xfce-perchannel-xml/xsettings.xml"
STRING="<property name="ThemeName" type="string" value="Glacier"/>"
if grep -q "$STRING" "$FILE" ; then
"$HOME/.config/lilidog-themes/anolis-theme"
else
"$HOME/.config/lilidog-themes/glacier-theme"
fi
Please note* "anolis-theme" and "glacier-theme" are simple theme scripts containing the lines to complete the change for all the necessary programs.
The theme scripts all contain simple one liners that could be used directly if required for some reason, but using the 'theme' scripts will allow me to set up a way for users to pick which two themes they want to use for the defaults, and change at will.
Here's an example of the lines used.
#!/bin/bash
xfconf-query -c xsettings -p /Net/ThemeName -s "Anolis"
xmlstarlet ed -L -N o="http://openbox.org/3.4/rc" -u '/o:openbox_config/o:theme/o:name' -v "Anolisbox" ~/.config/openbox/rc.xml
openbox --reconfigure
sed -i "s/color_scheme=.*/color_scheme=Anolis.conf/g" ~/.config/geany/geany.conf
jgmenu_run init --apply-obtheme
xfce4-term-colors anolis
Any thoughts or fixes much appreciated!
Last edited by sleekmason (2022-08-07 13:08:13)
Offline
Self modifying code!
@sleek, I can't grasp the question, can you rephrase / convert to simplest possible question / version of the problem?
This helps https://unix.stackexchange.com/question … ash-script ?
Last edited by brontosaurusrex (2022-07-31 17:05:04)
Offline
@sleek, I can't grasp the question, can you rephrase / convert to simplest possible question / version of the problem?
Yes:) I led with the simple version first, and then thought "what if they need the particulars?" lol. Anyway, basically This is it in a nutshell even though wrong:
#!/bin/bash
#
FILE="$HOME/.config/xfce4/xfconf/xfce-perchannel-xml/xsettings.xml"
STRING="<property name="ThemeName" type="string" value="Glacier"/>"
if grep -q "$STRING" "$FILE" ; then
xfconf-query -c xsettings -p /Net/ThemeName -s "Anolis"
else
xfconf-query -c xsettings -p /Net/ThemeName -s "Glacier"
fi
What I am Trying To Do:
Basically, regardless of which theme is currently active, (meaning not even one of the two themes list above), make an initial switch to Glacier (Light theme) and then on the subsequent press, toggle back to either the previously enabled theme (preferable), or another theme that can be a choice, in this particular case, Anolis (dark theme).
This will/could/should be used by the press of a tint2 icon, a keybind, or whatever else, so that in times of weirdness during dark theme use, like, trying to read something with strange colors in thunderbird, you just hit the button, first switching to the light theme chosen, and then when finished, either returning to the original theme (much preferable), or at the least, have another 'chosen' theme to return to on toggle. In the example case, 'Anolis'
So, in the post above this one, Instead of toggling an 'xfconf-query' line, I'll actually be toggling a script with several lines inside to make the complete theme change.
*EDIT
So in actual terms I would be trying to:
#!/bin/bash
#
## Not sure I even need to refer to $FILE and $STRING if changing back and forth between two
FILE="$HOME/.config/xfce4/xfconf/xfce-perchannel-xml/xsettings.xml"
STRING="<property name="ThemeName" type="string" value="Glacier"/>"
## set initial theme on button press
xfconf-query -c xsettings -p /Net/ThemeName -s "Glacier"
## set subsequent theme for repeat toggle use. If not the prior theme, then, Anolis
else
xfconf-query -c xsettings -p /Net/ThemeName -s "$my-old-theme" # or back to Anolis, a second chosen theme
fi
Last edited by sleekmason (2022-07-31 17:43:01)
Offline
Maybe the problem is that xfconf doesn't rewrite config files on the fly - it stores the current settings in memory, and - I think - writes them back later, if ever...
You've got a set of scripts, each of which does whatever is needed to apply a certain theme, right?
Assuming that those scripts themselves work OK, then grepping "$HOME/.config/xfce4/xfconf/xfce-perchannel-xml/xsettings.xml" isn't the test you need. Probably there's an xfconf-query you can run instead?
Another problem, though, is that openbox's theming won't be covered by xfconf. If this is just a quick theme-switch to read a bit of text, then maybe you can let the OB theme stay the way it is, just switch the GTK theme? The CLI equivalent of opening the XFCE theme GUI and choosing a different theme?
This works OK?
xfconf-query -c xsettings -p /Net/ThemeName -s "Glacier"
If so, it just remains to get the current theme with xfconf-query and store it in a temporary file somewhere (eg ~/.cache/somedir), then refer to that to get back later.
BTW on my system 'xfconf-query -c xsettings -l' returns nothing. No theme set there.
Last edited by johnraff (2022-08-01 05:00:00)
...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), now on Bluesky, there's also some GitStuff )
Offline
sleekmason, I may have script for you. It swaps between Adwaita and Adwait-dark with a keybind. You do need to specify the themes you are changing in the script.
The script, which I call "switch"
#! /bin/bash
#import config file from your stored location
. ~/.config/switch.conf
#Convert rgba value to 0-255 range
LR="$(($LIGHT_RED/255))"
LG="$(($LIGHT_GREEN/255))"
LB="$(($LIGHT_BLUE/255))"
DR="$(($DARK_RED/255))"
DG="$(($DARK_GREEN/255))"
DB="$(($DARK_BLUE/255))"
# Set the variables according to the arguments
if [[ "$1" == "light" ]]; then
#settings are same for dark
#xfce4 settings
xfconf-query -c xsettings -p /Net/ThemeName -s "$LIGHT_THEME"
#icon pack
xfconf-query -c xsettings -p /Net/IconThemeName -s "$LIGHT_ICON"
#This is for panel 0 only, if you have more than 1 panels repeat the code
#below replacing panel-0 by panel-1 and so on
#Repeat this for dark theme too
sed -i "s/^ColorForeground=.*/ColorForeground=$XFCE4_TERMINAL_LIGHT_TEXT/" ~/.config/xfce4/terminal/terminalrc
sed -i "s/^ColorBackground=.*/ColorBackground=$XFCE4_TERMINAL_LIGHT_BACKGROUND/" ~/.config/xfce4/terminal/terminalrc
sed -i "s/^ColorPalette=.*/ColorPalette=$XFCE4_TERMINAL_LIGHT_PALETTE/" ~/.config/xfce4/terminal/terminalrc
elif [[ "$1" == "dark" ]]; then
xfconf-query -c xsettings -p /Net/ThemeName -s "$DARK_THEME"
xfconf-query -c xsettings -p /Net/IconThemeName -s "$DARK_ICON"
sed -i "s/^ColorForeground=.*/ColorForeground=$XFCE4_TERMINAL_DARK_TEXT/" ~/.config/xfce4/terminal/terminalrc
sed -i "s/^ColorBackground=.*/ColorBackground=$XFCE4_TERMINAL_DARK_BACKGROUND/" ~/.config/xfce4/terminal/terminalrc
sed -i "s/^ColorPalette=.*/ColorPalette=$XFCE4_TERMINAL_DARK_PALETTE/" ~/.config/xfce4/terminal/terminalrc
fi
The switch.conf
# -----------------------------System Properties-------------------------------
# These are the property values xfce4 uses to determine display configuration.
# Modify thse properties if you get a 'property does not exist on channel' error.
# See the panel number you want to modify using the GUI:
# $ xfce4-panel -p
PANEL_NUMBER=1
# See the value you need using the command:
# $ xfconf-query -c xfce4-desktop -l
# The output will be something like this - /backdrop/screen0/monitoreDP1/*
# Here, monitoreDP1 is my required display port
DISPLAY_PORT="monitoreDP1"
# Modify this if you have multiple screens (if you need to)
SCREEN="screen0"
# --------------------------------Light Config---------------------------------
# Light mode theme
LIGHT_THEME="Adwaita"
# Light mode icon pack
LIGHT_ICON="Papirus-Light"
#Light mode window manager theme
LIGHT_WM_THEME="Greybird-dark-accessibility"
# color for xfce-panel: light mode
# Must be a value 0-255
LIGHT_RED=85
LIGHT_GREEN=85
LIGHT_BLUE=85
#Must be 0-1
LIGHT_OPACITY=1
#Full path to your wallpaper
#For light. See below for dark
LIGHT_WALLPAPER="/path-to-image"
# if a colorscheme has both light and dark variants, the script automatically
# changes background value to 'set background=light' in the vimrc file
# so simply including the colorscheme name here will do
# add your colorschemes to ~/.vim/colors/
VIM_LIGHT_COLORSCHEME="PaperColor"
# terminal background and text colors, for xfce4 terminal
XFCE4_TERMINAL_LIGHT_BACKGROUND="#dcdcdc"
XFCE4_TERMINAL_LIGHT_TEXT="#111111"
XFCE4_TERMINAL_LIGHT_PALETTE="rgb(63,63,63);rgb(112,80,80);rgb(96,180,138);rgb(223,175,143);rgb(154,184,215);rgb(220,140,195);rgb(37,138,142);rgb(220,220,220);rgb(112,144,128);rgb(220,163,163);rgb(210,228,219);rgb(240,223,175);rgb(148,191,243);rgb(236,147,211);rgb(37,138,142);rgb(255,255,255)"
# --------------------------------Dark Config---------------------------------
# Dark mode theme
DARK_THEME="Adwaita-dark"
# Dark mode icon pack
DARK_ICON="Papirus-Dark"
#Dark mode window manager theme
DARK_WM_THEME="Greybird-dark-accessibility"
# color for xfce-panel: dark mode
# Must be a value 0-255
DARK_RED=48
DARK_GREEN=48
DARK_BLUE=48
#Must be 0-1
DARK_OPACITY=1
DARK_WALLPAPER="/path-to-image"
# add your colorschemes to ~/.vim/colors/
VIM_DARK_COLORSCHEME="monochrome"
# terminal background and text colors, for xfce4 terminal
XFCE4_TERMINAL_DARK_BACKGROUND="#111111"
XFCE4_TERMINAL_DARK_TEXT="#dcdcdc"
XFCE4_TERMINAL_DARK_PALETTE="rgb(63,63,63);rgb(112,80,80);rgb(96,180,138);rgb(223,175,143);rgb(154,184,215);rgb(220,140,195);rgb(147,224,227);rgb(220,220,220);rgb(112,144,128);rgb(220,163,163);rgb(210,228,219);rgb(240,223,175);rgb(148,191,243);rgb(236,147,211);rgb(147,224,227);rgb(255,255,255)"
I use this solely for swapping light vs. dark (which is rare I might add) when the glare is too much in the room so the terminal additions are superfluous to requirements.
Also, I have zero input in the creation of this. I hope this helps somewhat and I actually grasped what you required.
"All we are is dust in the wind, dude"
- Theodore "Ted" Logan
"Led Zeppelin didn't write tunes that everybody liked, they left that to the Bee Gees."
- Wayne Campbell
Offline
This works OK?
xfconf-query -c xsettings -p /Net/ThemeName -s "Glacier"
If so, it just remains to get the current theme with xfconf-query and store it in a temporary file somewhere (eg ~/.cache/somedir), then refer to that to get back later.
Weird how the brain works. Everything clicked into place for me as far as using the previous theme and how to do it. Okay, I have something to work with. The toggle part might still be a problem, but I've got a plan now. @Dobbie03 posted a script that looks useful as well:)
You've got a set of scripts, each of which does whatever is needed to apply a certain theme, right?
Yes, they incorporate all the changes necessary, so I will actually be calling between the two scripts.
BTW on my system 'xfconf-query -c xsettings -l' returns nothing. No theme set there.
I'm using xfce4-settings with their daemon active in autostart:
xfsettingsd --daemon &
Aside from the terminal, there is a graphical editor for xfconf-query as one of the tools:) Really not a bad setup. Anyway, allows for changing themes on the fly. enter:
xfconf-query -c xsettings -p /Net/ThemeName -s "Glacier"
and the system immediately switches to Glacier. My 'theme' scripts are just basic 'one liners' that allow for changing the ENTIRE theme on the fly, from openbox and jgmenu, to xfce4-terminal and the gtk themes. Better yet, I've made the scripts accessible (.config) so people could add other items to them, like wallpapers, or activating/un-activating sounds, font size, whatever, when changing themes.
I'll see what I can come up with and post back:)
Offline
sleekmason, I may have script for you. It swaps between Adwaita and Adwait-dark with a keybind. You do need to specify the themes you are changing in the script.
The script, which I call "switch"
#! /bin/bash #import config file from your stored location . ~/.config/switch.conf #Convert rgba value to 0-255 range LR="$(($LIGHT_RED/255))" LG="$(($LIGHT_GREEN/255))" LB="$(($LIGHT_BLUE/255))" DR="$(($DARK_RED/255))" DG="$(($DARK_GREEN/255))" DB="$(($DARK_BLUE/255))" # Set the variables according to the arguments if [[ "$1" == "light" ]]; then #settings are same for dark #xfce4 settings xfconf-query -c xsettings -p /Net/ThemeName -s "$LIGHT_THEME" #icon pack xfconf-query -c xsettings -p /Net/IconThemeName -s "$LIGHT_ICON" #This is for panel 0 only, if you have more than 1 panels repeat the code #below replacing panel-0 by panel-1 and so on #Repeat this for dark theme too sed -i "s/^ColorForeground=.*/ColorForeground=$XFCE4_TERMINAL_LIGHT_TEXT/" ~/.config/xfce4/terminal/terminalrc sed -i "s/^ColorBackground=.*/ColorBackground=$XFCE4_TERMINAL_LIGHT_BACKGROUND/" ~/.config/xfce4/terminal/terminalrc sed -i "s/^ColorPalette=.*/ColorPalette=$XFCE4_TERMINAL_LIGHT_PALETTE/" ~/.config/xfce4/terminal/terminalrc elif [[ "$1" == "dark" ]]; then xfconf-query -c xsettings -p /Net/ThemeName -s "$DARK_THEME" xfconf-query -c xsettings -p /Net/IconThemeName -s "$DARK_ICON" sed -i "s/^ColorForeground=.*/ColorForeground=$XFCE4_TERMINAL_DARK_TEXT/" ~/.config/xfce4/terminal/terminalrc sed -i "s/^ColorBackground=.*/ColorBackground=$XFCE4_TERMINAL_DARK_BACKGROUND/" ~/.config/xfce4/terminal/terminalrc sed -i "s/^ColorPalette=.*/ColorPalette=$XFCE4_TERMINAL_DARK_PALETTE/" ~/.config/xfce4/terminal/terminalrc fi
The switch.conf
# -----------------------------System Properties------------------------------- # These are the property values xfce4 uses to determine display configuration. # Modify thse properties if you get a 'property does not exist on channel' error. # See the panel number you want to modify using the GUI: # $ xfce4-panel -p PANEL_NUMBER=1 # See the value you need using the command: # $ xfconf-query -c xfce4-desktop -l # The output will be something like this - /backdrop/screen0/monitoreDP1/* # Here, monitoreDP1 is my required display port DISPLAY_PORT="monitoreDP1" # Modify this if you have multiple screens (if you need to) SCREEN="screen0" # --------------------------------Light Config--------------------------------- # Light mode theme LIGHT_THEME="Adwaita" # Light mode icon pack LIGHT_ICON="Papirus-Light" #Light mode window manager theme LIGHT_WM_THEME="Greybird-dark-accessibility" # color for xfce-panel: light mode # Must be a value 0-255 LIGHT_RED=85 LIGHT_GREEN=85 LIGHT_BLUE=85 #Must be 0-1 LIGHT_OPACITY=1 #Full path to your wallpaper #For light. See below for dark LIGHT_WALLPAPER="/path-to-image" # if a colorscheme has both light and dark variants, the script automatically # changes background value to 'set background=light' in the vimrc file # so simply including the colorscheme name here will do # add your colorschemes to ~/.vim/colors/ VIM_LIGHT_COLORSCHEME="PaperColor" # terminal background and text colors, for xfce4 terminal XFCE4_TERMINAL_LIGHT_BACKGROUND="#dcdcdc" XFCE4_TERMINAL_LIGHT_TEXT="#111111" XFCE4_TERMINAL_LIGHT_PALETTE="rgb(63,63,63);rgb(112,80,80);rgb(96,180,138);rgb(223,175,143);rgb(154,184,215);rgb(220,140,195);rgb(37,138,142);rgb(220,220,220);rgb(112,144,128);rgb(220,163,163);rgb(210,228,219);rgb(240,223,175);rgb(148,191,243);rgb(236,147,211);rgb(37,138,142);rgb(255,255,255)" # --------------------------------Dark Config--------------------------------- # Dark mode theme DARK_THEME="Adwaita-dark" # Dark mode icon pack DARK_ICON="Papirus-Dark" #Dark mode window manager theme DARK_WM_THEME="Greybird-dark-accessibility" # color for xfce-panel: dark mode # Must be a value 0-255 DARK_RED=48 DARK_GREEN=48 DARK_BLUE=48 #Must be 0-1 DARK_OPACITY=1 DARK_WALLPAPER="/path-to-image" # add your colorschemes to ~/.vim/colors/ VIM_DARK_COLORSCHEME="monochrome" # terminal background and text colors, for xfce4 terminal XFCE4_TERMINAL_DARK_BACKGROUND="#111111" XFCE4_TERMINAL_DARK_TEXT="#dcdcdc" XFCE4_TERMINAL_DARK_PALETTE="rgb(63,63,63);rgb(112,80,80);rgb(96,180,138);rgb(223,175,143);rgb(154,184,215);rgb(220,140,195);rgb(147,224,227);rgb(220,220,220);rgb(112,144,128);rgb(220,163,163);rgb(210,228,219);rgb(240,223,175);rgb(148,191,243);rgb(236,147,211);rgb(147,224,227);rgb(255,255,255)"
I use this solely for swapping light vs. dark (which is rare I might add) when the glare is too much in the room so the terminal additions are superfluous to requirements.
Also, I have zero input in the creation of this. I hope this helps somewhat and I actually grasped what you required.
Yes! I do believe this will help, if not solve what I am trying to do. Thank you:) I'll post back whatever I get out of all this. I'm currently using a couple of keybinds to switch back and forth and really dig the fast change. I work on my patio out front a lot and when the sun enters the picture, I sometimes find it easier on the eyes with the light theme:) It just seems like a nifty feature to have.
Offline
Okie dokie, The part I thought I had beat, I most certainly do not. The disaster below actually works as planned for the toggle though, and all the extra info is just me trying to figure it.
Basically right now I have a toggle that will change ANY currently activated theme to "light-theme-glacier", and then on second key press, will change it to "dark-theme-anolis", rinse and repeat. I could probably make this work but it is not ideal.
Where I need help is how to extract just the theme name from either:
$HOME/.config/xfce4/xfconf/xfce-perchannel-xml/xsettings.xml <--easier maybe?
or:
$HOME/.config/openbox/rc.xml <-- I only know how to grab the line # rather than pattern.
And then insert that name back into the script itself, but this alludes me as well. Sed? awk?
My beginning attempts to get the theme name to ~/list.txt are pretty feable as you can see in the script.
Anyhow, If somebody knows how to grab the theme name properly, cut down, and/or appending the "switch" script itself afterwards with the "themename" it would be of huge help . . unless some other idea?
#!/bin/bash
#
FILE="$HOME/.config/openbox/rc.xml"
# Cp current theme name in ~/.config/openbox/rc.xml
# sed -n '45p' $HOME/.config/openbox/rc.xml > list.txt
grep -Rw ~/.config/xfce4/xfconf/xfce-perchannel-xml/xsettings.xml -e "ThemeName" | cut -b 53- > list.txt
## If Glacier, switch to $theme:
if grep -w "Glacierbox" "$FILE"; then
## Copy the name from ~/list.txt and insert into the below field where anolis is.
"$HOME/.config/lilidog-themes/anolis-theme"
# If OTHER theme, switch to Glacier:
elif grep -v -w "Glacierbox" "$FILE"; then
"$HOME/.config/lilidog-themes/glacier-theme"
fi
Last edited by sleekmason (2022-08-02 19:25:15)
Offline
Don't forget that Openbox theme names can be different from GTK theme names.
I think you're basically interested in the GTK theme here, right?
Since you're using xfsettingsd and can switch GTK themes on the fly (BL uses xsettingsd), maybe this would work to find the currently used theme name:
xfconf-query -c xsettings -p /Net/ThemeName
??
---
A bit off topic, but are all your theme-setting scripts pretty much the same? If so, would there be something to be said for making just one script eg themesetter and passing it the name of the theme to set like 'themesetter glacier'?
But, as you said, individual scripts in ~/.config might make it easier for users to tweak.
...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), now on Bluesky, there's also some GitStuff )
Offline
Don't forget that Openbox theme names can be different from GTK theme names.
I think you're basically interested in the GTK theme here, right?
Since you're using xfsettingsd and can switch GTK themes on the fly (BL uses xsettingsd), maybe this would work to find the currently used theme name:xfconf-query -c xsettings -p /Net/ThemeName
??
---
A bit off topic, but are all your theme-setting scripts pretty much the same? If so, would there be something to be said for making just one script eg themesetter and passing it the name of the theme to set like 'themesetter glacier'?
But, as you said, individual scripts in ~/.config might make it easier for users to tweak.
Yes, to complicate matter a bit, I am having to grep the theme name from Openbox rather than xsettings because for some reason when grepping ~/.config/xfce4/xfconf/xfce-perchannel-xml/xsettings.xml, a 5 second or so delay is created and ruins the ability to toggle back and forth. Just calling xfconf-query in a one liner does not cause any issues, so all of the "theme" scripts are good to go. Not ideal, but doable if creating separate theme scripts.
Lol. Of course.
xfconf-query -c xsettings -p /Net/ThemeName
The setup I have now for making theme changes uses individual scripts to call the necessary changes for each theme. I then have a yad dialog where you can chose any of the themes at will.
So, to change a complete theme including openbox, gtk, terminal, geany and jgmenu, you are only two clicks away, one for the "themes" dialog, and one to choose a complete theme.
I keep the theme scripts in ~.config for user adjustment, as any aspect you can change on the fly can be added. Pretty cool really. Pick wallpapers, sounds, font changes, anything can be assigned to any theme, or users can make their own.
In the case of the script I'm trying to make here? After getting used to changing themes at will, it just makes sense to have a light/dark toggle as well, and is probably more useful once people decide what they want to use theme wise.
Script wise, my concept for returning to the "old" dark theme after switching to light, is to replace the name directly in the script itself whilst making the switch to "light"
This means using a "scripted" light theme, but hopefully returning to whatever dark theme you were using before. As I have it right now, It simply selects the chosen light theme on first press, but then to a chosen dark theme as well. But to do it right?
This means grabbing the "old" name with:
xfconf-query -c xsettings -p /Net/ThemeName
And then using sed? to replace the whole line but with the "old" name and removing the capitalization. <-- Best I have at the moment.
Anyhow, I'll keep plugging away at this. If you or anyone else has it in the bag so to speak, please post the answer. I would think it would be super easy to use for any distro so long as you can make changes on the fly for all the different theme items. My thinking is maybe a panel button and a keybind if this can be made.
Here's the updated script.
#!/bin/bash
#
FILE="$HOME/.config/openbox/rc.xml"
# If Glacierbox found, then:
if grep -w "Glacierbox" "$FILE"; then
"$HOME/.config/lilidog-themes/anolis-theme"
# If Glacierbox NOT found, then:
xfconf-query -c xsettings -p /Net/ThemeName > list.txt # Theme name to ~/list.txt (change later)
sed -i 's/[A-Z]/\L&/g' list.txt # Replace capitalization.
# Replace line 7 with the corrected name
elif grep -v -w "Glacierbox" "$FILE"; then
"$HOME/.config/lilidog-themes/glacier-theme"
fi
Last edited by sleekmason (2022-08-02 19:58:13)
Offline
I feel like I'm pretty close.
#!/bin/bash
#
FILE="$HOME/.config/openbox/rc.xml"
# If Glacierbox found, then:
if grep -w "Glacierbox" "$FILE"; then
"$HOME/.config/lilidog-themes/anolis-theme"
# If Glacierbox NOT found, then:
xfconf-query -c xsettings -p /Net/ThemeName > list.txt # Theme name to ~/bin.
sed -i 's/[A-Z]/\L&/g' list.txt # Replace capitalization.
# Replace line 7 with the corrected name
elif grep -v -w "Glacierbox" "$FILE"; then
"$HOME/.config/lilidog-themes/glacier-theme"
fi
trans=grep -w ~/list.txt
sed -i "s/$HOME/lilidog-themes.*/$HOME/lilidog-themes$trans-theme/g" "$FILE"
#sed -i "0,/$HOME/lilidog-themes/{s/$HOME/lilidog-themes/.*/$HOME/lilidog-themes/${trans}/-theme}" $FILE
^^These last lines are how I think I can reinsert the proper name into the script, but I do not know the proper way to lay out the
trans=
properly with the right code to get the name, and then any corrections in the sed line to make it happen.
The second sed line will allow to choose only the first occurrence of the line rather than both.
So basically, How do I write the "trans=" line correctly to grab the word stored in ~/list.txt.
After that, it is just playing with the sed line to get it correct. Please help me to get the trans line correct!
Offline
There's more to consider here as well. I can't go adding "theme" to the line I'm wanting to change in the script, as it won't work for every gtk-theme unless they are named the same and for most themes, they are not.
This necessitates the need to rename them all, which wouldn't be a factor for others, so good on that. All of my "theme" script names currently end with "-theme" and really, they just need to be the name of the theme.
Also, I obviously then can't work off of Openbox. That means working only from ~/.config/xfce4/xfconf/xfce-perchannel-xml/xsettings.xml. However, using grep with the xsettings file causes a delay between toggle presses of several seconds to make the changes when working with xsettings.
This doesn't happen when using Openbox. Is there perhaps a way to accomplish this using a different grep option or something else entirely that doesn't cause the delay after the toggle is pressed?
So right now just a few things.
How to get "trans" in the script to give the correct name and be placed in the sed line.
Switch solely to ~/.config/xfce4/xfconf/xfce-perchannel-xml/xsettings.xml for grabbing info, but without the delay caused by the current grep method.
Yeah, this may end up getting binned for a while. A couple of keybinds does basically the same thing and I learned a groovy new toggle method.
Last edited by sleekmason (2022-08-02 22:12:31)
Offline
This is now corrected to only using xsettings and I changed all the theme scripts to match the gtk name exactly, so no capitalization magic needed. But unfortunately there is still the delay between toggles using grep, or at least what I have tried, namely just grep, and grep -w. The delay is about 5 seconds long.
Don't even know if grep is the culprit.
#!/bin/bash
#
FILE="$HOME/.config/xfce4/xfconf/xfce-perchannel-xml/xsettings.xml"
# If Glacier found, then:
if grep "Glacier" "$FILE"; then
"$HOME/.config/lilidog-themes/Anolis"
# If Glacierbox NOT found, then:
xfconf-query -c xsettings -p /Net/ThemeName > list.txt # Theme name to ~/list. change to tmp later
elif grep -v "Glacier" "$FILE"; then
"$HOME/.config/lilidog-themes/Glacier"
fi
trans="grep $HOME/list.txt" ##Is it possible to use the xfconf-query line directly here?
sed -i "0,/\$HOME\/.config\/lilidog-themes\//{s/\$HOME\/.config\/lilidog-themes\/.*/\$HOME\/.config\/lilidog-themes\/\${trans}/}" "$HOME/bin/switch"
Really, at this point, I just need the trans line correct for it to work, and then focus on the toggle delay issue.
* Edit - I tried copying the xsettings file to tmp and then making the changes from the tmp file, but had the same delay result.
Last edited by sleekmason (2022-08-03 02:04:28)
Offline
I'm probably overlooking some important factors, but this all looks a bit complicated.
Have I got the task right here?
> Using a dark GTK theme, and text is hard to read. Temporarily switch to a light GTK theme, then one more click to go back to the previous theme when you're done.
Why not leave Openbox and grepping config files out of it, and just do:
#!/bin/bash
default_light_theme=Glacier # some installed GTK theme, make sure capitalization is correct
temp_file=~/.cache/temp_theme # this must be some fixed predetermined location so the next invocation of the script can find it
if [[ -e $temp_file ]] # toggling back to original state
then
xfconf-query -c xsettings -p /Net/ThemeName -s "$(<"$temp_file")"
rm "$temp_file"
else
xfconf-query -c xsettings -p /Net/ThemeName > "$temp_file"
xfconf-query -c xsettings -p /Net/ThemeName -s "$default_light_theme"
fi
...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), now on Bluesky, there's also some GitStuff )
Offline
I'm probably overlooking some important factors, but this all looks a bit complicated.
Have I got the task right here?
> Using a dark GTK theme, and text is hard to read. Temporarily switch to a light GTK theme, then one more click to go back to the previous theme when you're done.Why not leave Openbox and grepping config files out of it, and just do:
#!/bin/bash default_light_theme=Glacier # some installed GTK theme, make sure capitalization is correct temp_file=~/.cache/temp_theme # this must be some fixed predetermined location so the next invocation of the script can find it if [[ -e $temp_file ]] # toggling back to original state then xfconf-query -c xsettings -p /Net/ThemeName -s "$(<"$temp_file")" rm "$temp_file" else xfconf-query -c xsettings -p /Net/ThemeName > "$temp_file" xfconf-query -c xsettings -p /Net/ThemeName -s "$default_light_theme" fi
Yes you have the idea! ^ This works great for the gtk theme itself, but I'm needing to change 5 items at the same time.
For Anolis for instance:
# Change gtktheme
xfconf-query -c xsettings -p /Net/ThemeName -s "Anolis"
# Change openbox theme
xmlstarlet ed -L -N o="http://openbox.org/3.4/rc" -u '/o:openbox_config/o:theme/o:name' -v "Anolisbox" ~/.config/openbox/rc.xml
openbox --reconfigure
## Change Geany theme
sed -i "s/color_scheme=.*/color_scheme=Anolis.conf/g" ~/.config/geany/geany.conf
# Change jgmenu theme
#jgmenu_run gtktheme
jgmenu_run init --apply-obtheme
## Change xfce4-terminal theme
xfce4-term-colors anolis
These are roughly the same changes for all the themes at the moment. If I can incorporate these into your script as well, it would work, but if I can do it through the "themes" scripts, then 'anybody' will be able to make a theme-file of their own design.
Can the script you wrote be adapted to do the same with "Theme" scripts in .config? <--This would be the ideal solution for sure.
This makes it not just light/dark, but specialized/dark if you want a specialized theme to use.
The script I'm making above works as far as I can tell, accept for getting the name in "trans"
trans= ?
^Can't I just trans = list.txt and sed it to the script? Everything else is in place but that.
Last edited by sleekmason (2022-08-03 11:39:56)
Offline
^ This works great for the gtk theme itself, but I'm needing to change 5 items at the same time.
But what I don't get is why you need to change anything else beside the GTK theme. Isn't this just a temporary switch to make a textbox or something readable? Then user will go back to where they were before. Does it matter that much if the openbox window, geany etc etc don't match for that 5 min or so?
...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), now on Bluesky, there's also some GitStuff )
Offline
sleekmason wrote:^ This works great for the gtk theme itself, but I'm needing to change 5 items at the same time.
But what I don't get is why you need to change anything else beside the GTK theme. Isn't this just a temporary switch to make a textbox or something readable? Then user will go back to where they were before. Does it matter that much if the openbox window, geany etc etc don't match for that 5 min or so?
Heh:)
None of it is necessary. It's all about the learning for me. Each new item I learn scripting, I put to work. And this one would be no different. I can already envision several other offshoot concepts based on the actual toggle script itself.
To answer the question though. It may not be for just a second or two. For instance, I work on my front patio a lot, and am constantly changing to the light theme based on sun light levels. Changing the whole theme is simply the best way if I can get it done.
Also, this is really about allowing users to create their own "alternate" theme they can switch to. Doesn't have to be light. Maybe its the theme that has the larger text and sounds associated. Maybe a work VS play theme. And for me? Maybe not for the themes at all, but some other use! I just like to learn, and this particular script is part of that area:)
If you can figure it, I sure would appreciate it. I know there are probably a couple dozen folks that regularly visit BL that understand all of this. I wish they would involve themselves more.
So much cool stuff to do. Why are we all here if not to learn and do more?
Offline
None of it is necessary. It's all about the learning for me.
...
I know there are probably a couple dozen folks that regularly visit BL that understand all of this. I wish they would involve themselves more.
I think if you want people to help you with an issue, it's best if you lay out a very specific goal right from the start.
PS the BL BLOB utility was developed by Damo to deal with this kind of situation. It does a pretty good job now, but turned out to be quite complicated! (2300 line script + config directories...) If you've got a BL install to hand you might like to give it a try.
Last edited by johnraff (2022-08-04 23:49:31)
...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), now on Bluesky, there's also some GitStuff )
Offline
sleekmason wrote:None of it is necessary. It's all about the learning for me.
...
I know there are probably a couple dozen folks that regularly visit BL that understand all of this. I wish they would involve themselves more.I think if you want people to help you with an issue, it's best if you lay out a very specific goal right from the start.
PS the BL BLOB utility was developed by Damo to deal with this kind of situation. It does a pretty good job now, but turned out to be quite complicated! (2300 line script + config directories...) If you've got a BL install to hand you might like to give it a try.
Thank you! Ultimately, no worries. I have two keybinds set up making an easy switch, and can certainly use what I have so far for a couple of uses, including a basic light dark toggle. Life is good:)
Offline