Need a simple cinnamon applet

I need a simple applet that executes a command when clicked and executes the second command when clicked again. I will use it to change themes, icons, cursors, window borders (in short global theme switcher between light and dark mode).
Can I make an applet for this?

If yes, How?

The structure will be:
Click > toggle theme to a different set.

1 Like

I would do it different.
I would create a shell script, which includes the comnands you need to run, then bind it to a shortcut key. (e.g. ctrl-f2)
The script could check for presence of a file for example, then execute commands A, and delete the file, or execute commands B and create that file: thus achieving the toggle effect.
Somehing like:

#! /bin/bash
if [ -f "flag" ]; then
    echo "flag exists."
    rm flag
# put here the useful commands
else
    echo "flag does not exist."
    touch flag
#put here other useful commands
fi

Alternatively it could check for a value of something, that reliably indicates the current state, and then act accordingly. My screen rotating script follows this logic:

#!/bin/bash
lookfor='x1080'
lookfor2='x1920'
result=$(xrandr --listactivemonitors)
case $result in
*$lookfor*)
 xrandr -o left;
;;
*$lookfor2*)
 xrandr -o normal;
;;
esac

This is toggling the screen between portrait/landscape.

2 Likes

You gave me an idea, thanks!!! :star_struck:
I see, I can do a similar thing in my MATE DE with a series of
dconf write /org/mate/...
commands…

#!/bin/dash
# Kill if already running
if pidof -o %PPID -x "${0##*/}"; then
  exit 1
fi
# Start loop
while :
do
# What time is it?
  CURRENT_TIME=$(date +%H%M)
  if [ -n "$NEXT_TIME" ] && [ "$CURRENT_TIME" -lt "$NEXT_TIME" ]; then
    sleep 60
    continue
  fi
# Depending on time set THEME_CHOICE & NEXT_TIME
  if [ "$CURRENT_TIME" -ge 0000 ] && [ "$CURRENT_TIME" -lt 0200 ]; then
    THEME_CHOICE=Mint-Y-Dark-Red
    NEXT_TIME=0200
  elif [ "$CURRENT_TIME" -ge 0200 ] && [ "$CURRENT_TIME" -lt 0600 ]; then
    THEME_CHOICE=Mint-Y-Dark-Purple
    NEXT_TIME=0600
  elif [ "$CURRENT_TIME" -ge 0600 ] && [ "$CURRENT_TIME" -lt 0930 ]; then
    THEME_CHOICE=Mint-Y-Dark-Aqua
    NEXT_TIME=0930
  elif [ "$CURRENT_TIME" -ge 0930 ] && [ "$CURRENT_TIME" -lt 1430 ]; then
    THEME_CHOICE=Mint-Y-Purple
    NEXT_TIME=1430
  elif [ "$CURRENT_TIME" -ge 1430 ] && [ "$CURRENT_TIME" -lt 1800 ]; then
    THEME_CHOICE=Mint-Y-Dark-Sand
    NEXT_TIME=1800
  elif [ "$CURRENT_TIME" -ge 1800 ] && [ "$CURRENT_TIME" -lt 2200 ]; then
    THEME_CHOICE=Mint-Y-Dark-Orange
    NEXT_TIME=2200
  elif [ "$CURRENT_TIME" -ge 2200 ] && [ "$CURRENT_TIME" -le 2359 ]; then
    THEME_CHOICE=Mint-Y-Dark-Grey
    NEXT_TIME=0000
  fi
# Set the chosen theme
  gsettings set org.cinnamon.desktop.interface gtk-theme "$THEME_CHOICE"
  gsettings set org.cinnamon.desktop.interface icon-theme "$THEME_CHOICE"
  gsettings set org.cinnamon.theme name "$THEME_CHOICE"
# Sleep
  sleep 60
done

Look at this script. It changes theme of cinnamon by time. I need to change theme with keyboard shortcuts. Can anyone help me with that??

1 Like

Sure. I looked at that script, and I see, the work is done on these lines:

gsettings set org.cinnamon.desktop.interface gtk-theme "$THEME_CHOICE"
gsettings set org.cinnamon.desktop.interface icon-theme "$THEME_CHOICE"
gsettings set org.cinnamon.theme name "$THEME_CHOICE"

I assume, you still want a toggle effect between 2 set of theme options?
So I provide you 3 scripts, themesaveA, themesaveB, and toggletheme.
Place these scripts into your home folder (but you can place them anywhere you like).
Set up your desktop theme as you like, then launch themesaveA. It will theoretically create a file for you in ~/.config, and store there the theme options it can read.
Then after that change your desktop theme to the other settings you would like, and launch themesaveB. If I did not mess up things, it will create another file for the alternative settings.
Then launch toggletheme script couple times, and watch, how it behaves, what it does.
If that is what you want to achieve, assign a keyboard shortcut to the toggletheme script.
Here’s an article about Cinnamons keyboard shortcuts, and how to add your own custom…

And now the scripts, first the themesaveA:

#! /bin/bash
gtk=$(gsettings get org.cinnamon.desktop.interface gtk-theme)
icon=$(gsettings get org.cinnamon.desktop.interface icon-theme)
theme=$(gsettings get org.cinnamon.theme name)
echo "gtk=\"$gtk\"" >~/.config/themea
echo "icon=\"$icon\"" >>~/.config/themea
echo "theme=\"$theme\"" >>~/.config/themea

The script themesaveB is the same, just output to a different file:

#! /bin/bash
gtk=$(gsettings get org.cinnamon.desktop.interface gtk-theme)
icon=$(gsettings get org.cinnamon.desktop.interface icon-theme)
theme=$(gsettings get org.cinnamon.theme name)
echo "gtk=\"$gtk\"" >~/.config/themeb
echo "icon=\"$icon\"" >>~/.config/themeb
echo "theme=\"$theme\"" >>~/.config/themeb

Now the toggle script:

#! /bin/bash
flag="$HOME/.config/themeflag"
if [ -f "$flag" ]; then
    rm $flag
    conf=~/.config/themea
else
    touch $flag
    conf=~/.config/themeb
fi
source $conf
gsettings set org.cinnamon.desktop.interface gtk-theme $gtk
gsettings set org.cinnamon.desktop.interface icon-theme $icon
gsettings set org.cinnamon.theme name $theme

I don’t have a Cinnamon, and I would not like to install it at the moment.
So, please, try these scripts. Copy/paste them into your favorite text editor, and save them accordingly. Don’t forget to chmod +x them!
If it works, as you whish it to work, then huuraay!!! :smiley:
If it doesn’t, let me know about the problem.
Also, attach any error message, as well as the ~/.config/themea and ~/.config/themeb file.
Good luck!
:wink:
Update… I did fthis or my MATE, it looks almost identical, except it uses dconf read and dconf write commands. Based on the bugs I found in my previous implementation, updated the above scripts.
I hope, it will work for you… :wink:

1 Like

Thank you very much! :heartpulse:

It works perfectly. I’ve also included cursor-theme and window-border theme.

#! /bin/bash
gtk=$(gsettings get org.cinnamon.desktop.interface gtk-theme)
icon=$(gsettings get org.cinnamon.desktop.interface icon-theme)
theme=$(gsettings get org.cinnamon.theme name)
window=$(gsettings get org.cinnamon.desktop.wm.preferences theme)
cursor=$(gsettings get org.cinnamon.desktop.interface cursor-theme)
echo "gtk=\"$gtk\"" >~/.config/themea
echo "icon=\"$icon\"" >>~/.config/themea
echo "theme=\"$theme\"" >>~/.config/themea
echo "window=\"$window\"" >>~/.config/themea
echo "cursor=\"$cursor\"" >>~/.config/themea

themeB

#! /bin/bash
gtk=$(gsettings get org.cinnamon.desktop.interface gtk-theme)
icon=$(gsettings get org.cinnamon.desktop.interface icon-theme)
theme=$(gsettings get org.cinnamon.theme name)
window=$(gsettings get org.cinnamon.desktop.wm.preferences theme)
cursor=$(gsettings get org.cinnamon.desktop.interface cursor-theme)
echo "gtk=\"$gtk\"" >~/.config/themeb
echo "icon=\"$icon\"" >>~/.config/themeb
echo "theme=\"$theme\"" >>~/.config/themeb
echo "window=\"$window\"" >>~/.config/themeb
echo "cursor=\"$cursor\"" >>~/.config/themeb

and toggle-theme

#! /bin/bash
flag="$HOME/.config/themeflag"
if [ -f "$flag" ]; then
    rm $flag
    conf=~/.config/themea
else
    touch $flag
    conf=~/.config/themeb
fi
source $conf
gsettings set org.cinnamon.desktop.interface gtk-theme $gtk
gsettings set org.cinnamon.desktop.interface icon-theme $icon
gsettings set org.cinnamon.theme name $theme
gsettings set org.cinnamon.desktop.wm.preferences theme $window
gsettings set org.cinnamon.desktop.interface cursor-theme $cursor

Then I’ve found these applets for cinnamon in the applet store. So Life’s Good now :wink:
And again Thank you very much @kovacslt

1 Like