gnome-switch-theme.sh (921B)
1 #!/usr/bin/env bash
2
3 # exit on error
4 set -eo pipefail
5
6 export XDG_RUNTIME_DIR="/run/user/$(id -u)"
7 export DBUS_SESSION_BUS_ADDRESS="unix:path=${XDG_RUNTIME_DIR}/bus"
8
9 # check whether input was given
10 if [ -z $1 ]; then
11 # get current GTK theme
12 target=$(gsettings get org.gnome.desktop.interface color-scheme)
13 else
14 target="$1"
15 fi
16
17 # If we want a dark theme, but the current theme is not, switch theme to dark
18 if [[ "$target" == "'prefer-light'" ]] || [[ "$target" == "dark" ]]; then
19 gsettings set org.gnome.desktop.interface color-scheme "prefer-dark"
20 echo "[✓] Switched gnome to dark!"
21
22 # If we want a light theme, but the current theme is not, switch theme to light
23 elif [[ "$target" == "'prefer-dark'" ]] || [[ "$target" == "light" ]]; then
24 gsettings set org.gnome.desktop.interface color-scheme "prefer-light"
25 echo "[✓] Switched gnome to light!"
26
27 else
28 echo "[-] Did not switch theme: $sys_theme"
29
30 fi