Skip to content

Commit 6bd5b9b

Browse files
committed
Add option to execute user script on mode change
Let the user execute custom commands on mode change, for example change wallpaper, terminal theme, etc.
1 parent 4c6ae90 commit 6bd5b9b

2 files changed

Lines changed: 45 additions & 0 deletions

File tree

README.adoc

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,43 @@ from the appropriate location:
5656
* Window manager theme
5757
** `xfwm4/general/theme`
5858

59+
The specified `UserScript` will be executed when switching the mode, you can use
60+
this for example to change the theme of the terminal, set desktop wallpaper,
61+
etc. You can use the variable `XFCE_NIGHT_MODE` in your script if you want to
62+
use the same script in both cases, for example:
63+
64+
....
65+
#!/bin/bash
66+
notify-send --icon "dialog-info" "Mode: $XFCE_NIGHT_MODE"
67+
....
68+
69+
=== Example `UserScript`
70+
71+
==== Change wallpaper
72+
73+
First you have to find the property of the wallpaper (this could be different on
74+
multi-monitor setup) by executing the command below then changing the wallpaper
75+
in _Desktop_ setting.
76+
77+
```
78+
xfconf-query --channel xfce4-desktop --monitor
79+
```
80+
81+
You have to execute the command below to set up the wallpaper for this desktop.
82+
83+
```
84+
xfconf-query --channel xfce4-desktop --property <property> --set </path/to/image.jpg>
85+
```
86+
87+
==== Change panel dark mode
88+
89+
You have to execute the command below to change the panel mode opposite to the
90+
windows mode (light windows, dark panel).
91+
92+
```
93+
xfconf-query --channel xfce4-panel --property /panels/dark-mode --set "$([ "$XFCE_NIGHT_MODE" = "day" ] && echo true || echo false)"
94+
```
95+
5996
=== Switch at a time specified by antoher program
6097

6198
For example, to use http://jonls.dk/redshift/[Redshift] or another program to

xfce4-night-mode.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ CURSOR_LIGHT="$(get_config 'Light/CursorTheme' 'string' $(xfconf-query --channel
105105
CURSOR_DARK="$(get_config 'Dark/CursorTheme' 'string' $(xfconf-query --channel xsettings --property /Gtk/CursorThemeName))"
106106
WM_LIGHT="$(get_config 'Light/WindowManagerTheme' 'string' $(xfconf-query --channel xfwm4 --property /general/theme))"
107107
WM_DARK="$(get_config 'Dark/WindowManagerTheme' 'string' $(xfconf-query --channel xfwm4 --property /general/theme))"
108+
USERSCRIPT_LIGHT="$(get_config 'Light/UserScript' 'string')"
109+
USERSCRIPT_DARK="$(get_config 'Dark/UserScript' 'string')"
108110

109111
mode="$(parse_args $@)"
110112

@@ -152,6 +154,12 @@ set_theme 'xfwm4' '/general/theme' "WM_$suffix"
152154

153155
set_config 'active' 'string' "$mode"
154156

157+
# Execute user script to change wallpaper, terminal theme, etc.
158+
userscript="USERSCRIPT_$suffix"
159+
if [ ! -z "${!userscript}" ]; then
160+
XFCE_NIGHT_MODE="$mode" eval "${!userscript}" 2>&1 > /dev/null
161+
fi
162+
155163
echo "<txt>$TEXT</txt>"
156164
echo "<txtclick>$0 toggle</txtclick>"
157165
echo "<tool>

0 commit comments

Comments
 (0)