Help with Cinnamon theme toggle script

Style your desktop
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Post Reply
minthelp777
Level 3
Level 3
Posts: 178
Joined: Mon Jul 29, 2024 8:18 pm

Help with Cinnamon theme toggle script

Post by minthelp777 »

I have a script that I use to toggle between light and dark Cinnamon themes, but it occasionally crashes Cinnamon (into "fallback" mode), which is frustrating because it resizes some windows when it does. I've used this script for about 2 years or so and it has always occasionally crashed Cinnamon. Not sure what causes the crash, and I've debugged it the best I know how. It doesn't seem to be memory related and I can't isolate it to one command.

The script also restarts Audacious (music player), which I usually have running, and applies a light/dark theme to that, as well. This is the only way I've found to change the Audacious skin with a script.

Am I using any commands that I shouldn't be or am I doing something incorrectly?

It works most of the time, but the crash is unexpected and I can't figure it out.

Thanks.

Code: Select all

#!/bin/bash

# Get current theme
theme=$(gsettings get org.cinnamon.theme name)
#echo "Current theme is $theme"

if [ $theme = "'Mint-Y-Aqua'" ]; then
    #echo "Setting evening theme..."
    # Set light coloured panel icon for timer applet
    # (This has to be done manually for this applet since it doesn't switch its symbolic icon)
    cp ~/timer_cinnamon_applet_stylesheet_light.css ~/.local/share/cinnamon/applets/cinnamon-timer@jake1164/3.4/stylesheet.css
    sleep 1.3
    # Controls:
    gsettings set org.cinnamon.desktop.interface gtk-theme "Mint-Y-Dark-Aqua"
    # This was missing for a long while, some applications wouldn't switch - but this fixed it.
    # Found it via the "Dark Mode" panel applet.
    gsettings set org.gnome.desktop.interface color-scheme prefer-dark
    # Mouse pointer:
    settings set org.cinnamon.desktop.interface cursor-theme 'DMZ-Black'
    # Desktop: (this changes the bottom bar, primarily)
    gsettings set org.cinnamon.theme name "Mint-Y-Dark-Aqua"
    sleep 1.3
    # Wallpaper:
    gsettings set org.cinnamon.desktop.background picture-uri 'file:///usr/share/backgrounds/linuxmint-ulyssa/echerkasski_countryside.jpg'
    sleep 1.3
    # Switch Xed editor theme to get light/dark Preview popups ('Preview' is when selecting a file and pressing Spacebar)
    # (From https://forums.linuxmint.com/viewtopic.php?t=356810 and https://askubuntu.com/questions/305225/how-to-clean-gedits-and-other-editors-findreplace-history and https://askubuntu.com/questions/487206/dconf-change-a-string-key, used gsettings list-recursively org.x.editor to get the list of all the keys for Xed)
    gsettings set org.x.editor.preferences.editor scheme "cobalt"
    sleep 1.3
    # Change Audacious media player theme and restart it to apply the change (from https://redmine.audacious-media-player.org/boards/1/topics/3001?r=3004)
    playback_status=$(audtool --playback-status)
    #echo $playback_status
    audtool config-set skins:skin "/usr/share/audacious/Skins/Default"
    sleep 1.3
    // Restart Audacious
    audtool --playback-pause
    audtool --shutdown
    sleep 1.3
    if [ $playback_status = "playing" ]; then
        audacious -p &  # Start Audacious playing since it was playing when it was stopped
    else
        audacious &
    fi
    sleep 1.3
else
    #echo "Setting daytime theme"
    # (This has to be done manually for this applet since it doesn't switch its symbolic icon)
    cp ~/timer_cinnamon_applet_stylesheet_dark.css ~/.local/share/cinnamon/applets/cinnamon-timer@jake1164/3.4/stylesheet.css
    sleep 1.3
    # Controls:
    gsettings set org.cinnamon.desktop.interface gtk-theme "Mint-Y-Aqua"
    # Have to set this when switching to light mode, or else prefer-dark won't work when switching to dark mode.
    gsettings set org.gnome.desktop.interface color-scheme prefer-light
    # Mouse pointer:
    settings set org.cinnamon.desktop.interface cursor-theme 'DMZ-Black'
    # Desktop: (this changes the bottom bar, primarily)
    gsettings set org.cinnamon.theme name "Mint-Y-Aqua"
    sleep 1.3
    # Wallpaper:
    gsettings set org.cinnamon.desktop.background picture-uri 'file:///usr/share/backgrounds/linuxmint-ulyana/aandrews_tree.jpg'
    sleep 1.3
    # Switch Xed editor theme to get light/dark Preview popups ('Preview' is when selecting a file and pressing Spacebar)
    # (From https://forums.linuxmint.com/viewtopic.php?t=356810 and https://askubuntu.com/questions/305225/how-to-clean-gedits-and-other-editors-findreplace-history and https://askubuntu.com/questions/487206/dconf-change-a-string-key, used gsettings list-recursively org.x.editor to get the list of all the keys for Xed)
    gsettings set org.x.editor.preferences.editor scheme "classic"
    sleep 1.3
    # Change Audacious media player theme and restart it to apply the change (from https://redmine.audacious-media-player.org/boards/1/topics/3001?r=3004)
    playback_status=$(audtool --playback-status)
    #echo $playback_status
    audtool config-set skins:skin "/usr/share/audacious/Skins/Classic"
    sleep 1.3
    audtool --playback-pause
    audtool --shutdown
    sleep 1.3
    if [ $playback_status = "playing" ]; then
        audacious -p &  # Start Audacious playing since it was playing when it was stopped
    else
        audacious &
    fi
    sleep 1.3
fi
JosephM
Level 7
Level 7
Posts: 1505
Joined: Sun May 26, 2013 6:25 pm

Re: Help with Cinnamon theme toggle script

Post by JosephM »

After it crashes, check ~/.xsession-errors. It often has details on what caused the crash.
When I give opinions, they are my own. Not necessarily those of any other Linux Mint developer or the Linux Mint project as a whole.
minthelp777
Level 3
Level 3
Posts: 178
Joined: Mon Jul 29, 2024 8:18 pm

Re: Help with Cinnamon theme toggle script

Post by minthelp777 »

JosephM wrote: Mon Sep 30, 2024 8:28 pm After it crashes, check ~/.xsession-errors. It often has details on what caused the crash.
Yeah, thanks, I've tried that. It wasn't helpful, unfortunately.

In fact, I've tried to watch the memory usage as it runs with code like this wrapped around every command, but it didn't tell me much, either:

Code: Select all

freeram=$(free -m | grep Swap | awk '{print ($3/$2)*100}')
echo "=== Free RAM is $freeram%" >> ~/.xsession-errors
echo $(date +%Y-%m-%d_%H:%M:%S) >> ~/.xsession-errors
minthelp777
Level 3
Level 3
Posts: 178
Joined: Mon Jul 29, 2024 8:18 pm

Re: Help with Cinnamon theme toggle script

Post by minthelp777 »

Anyone use a different way of switching themes (with one click) that doesn't crash Cinnamon?
Post Reply

Return to “Themes, Icons & Wallpaper”