[SOLVED] A way to schedule Cinnamon theme changes

Questions about other topics and general discussion about LMDE
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Bruce McL

[SOLVED] A way to schedule Cinnamon theme changes

Post by Bruce McL »

I’d like to have Cinnamon change appearance settings at different times of the day. For example, I use Mint Y dark. Here’s what I would like to have happen to the icons, controls, and desktop:

Aqua: 6am to 10am
Green: 10am to 2pm
Sand: 2pm to 6pm
Orange: 6pm to 10pm
Red: 10pm to 2am
Purple: 2am to 6am

Let me be clear about this: I don’t think this is important, or therapeutic, or serious. I think it would be fun! It would be a very simple clock. If you are working and you notice the appearance colors have changed twice, maybe it’s time for a break! :-)

I’m not asking for an addition to the settings, or any change to the official distro. If somebody would write a script with instructions on how to enable it, I would be happy.

Edit: the working script is in a post by smurphos on the second page of this thread:
viewtopic.php?p=1674417#p1674417
The post below that one has installation instructions.
Many thanks to smurphos for doing this.
Last edited by Bruce McL on Fri Aug 23, 2019 8:13 pm, edited 3 times in total.
User avatar
lsemmens
Level 11
Level 11
Posts: 3936
Joined: Wed Sep 10, 2014 9:07 pm
Location: Rural South Australia

Re: Looking for a hack to change appearance over time.

Post by lsemmens »

Not sure about themes but you can change your desktop background at regular intervals. Just right click on the desktop and then on Change desktop background, from there, you can set up a slideshow to change the background as often as you desire.
Fully mint Household
Out of my mind - please leave a message
Bruce McL

Re: Looking for a hack to change appearance over time.

Post by Bruce McL »

That’s an interesting idea, but I don’t think it would work out well for what I want.

Keeping the desktop picture slideshow in sync with the time of day might be difficult. I tend to use a gray desktop anyway.

There are other OSs that have “dynamic desktop” pictures that change based on the time of day, so it is a thing that some people do. I'm looking for a more subtle change - just the window dressing and icons.
User avatar
smurphos
Level 18
Level 18
Posts: 8501
Joined: Fri Sep 05, 2014 12:18 am
Location: Irish Brit in Portugal
Contact:

Re: Looking for a hack to change appearance over time.

Post by smurphos »

This should be achievable with a bit of bash scripting. Give me a day or three and when I've got some spare time I'll try and knock something up.
For custom Nemo actions, useful scripts for the Cinnamon desktop, and Cinnamox themes visit my Github pages.
Bruce McL

Re: Looking for a hack to change appearance over time.

Post by Bruce McL »

That's great! I was just staring to look into how to do this myself.
Step 1 - Find the command line commands to change the appearance settings. I think dconf and Dconf-editor would be helpful here.
Step 2 - Find out how to schedule something. I think people use cron for this.
That's about as far as I've gotten.
User avatar
Flemur
Level 20
Level 20
Posts: 10097
Joined: Mon Aug 20, 2012 9:41 pm
Location: Potemkin Village

Re: Looking for a hack to change appearance over time.

Post by Flemur »

I change my appearance over time by getting old!

I'll go away now...
Please edit your original post title to include [SOLVED] if/when it is solved!
Your data and OS are backed up....right?
User avatar
smurphos
Level 18
Level 18
Posts: 8501
Joined: Fri Sep 05, 2014 12:18 am
Location: Irish Brit in Portugal
Contact:

Re: Looking for a hack to change appearance over time.

Post by smurphos »

Bruce McL wrote: Thu Aug 15, 2019 11:41 am That's great! I was just staring to look into how to do this myself.
Step 1 - Find the command line commands to change the appearance settings. I think dconf and Dconf-editor would be helpful here.
Step 2 - Find out how to schedule something. I think people use cron for this.
That's about as far as I've gotten.
You are on the right lines.. :)

I'm not sure if cron or an always running background script is the best way to go - either approach could work.

You can also use the command gsettings to set the various theme elements.

eg.

gsettings set org.cinnamon.desktop.interface gtk-theme Mint-Y-Dark-Aqua

gsettings set org.cinnamon.theme name Mint-Y-Dark-Aqua
For custom Nemo actions, useful scripts for the Cinnamon desktop, and Cinnamox themes visit my Github pages.
Bruce McL

Re: Looking for a hack to change appearance over time.

Post by Bruce McL »

That’s good info, thanks!

That gets me halfway there.

I did some searching online and found an app called Gnome Schedule. It’s a graphical front end for cron. Unfortunately it’s not in the LMDE repositories. Doing more research, it looks like it's a bit old and has been dropped from many repositories. I think I can learn how to use crontab though. I'll do some studying on that.
Bruce McL

Re: Looking for a hack to change appearance over time.

Post by Bruce McL »

smurphos wrote: Thu Aug 15, 2019 12:53 pm
I'm not sure if cron or an always running background script is the best way to go - either approach could work.

You can also use the command gsettings to set the various theme elements.

eg.

gsettings set org.cinnamon.desktop.interface gtk-theme Mint-Y-Dark-Aqua

gsettings set org.cinnamon.theme name Mint-Y-Dark-Aqua
Those commands work - sort of. After I issue the commands in the terminal, I can open up the Settings app and see that the settings have changed. However, I have to log out and log back in to see the changes take effect. I think one more command is necessary to persuade Cinnamon to apply the changes immediately. I looked at gsettings options but I didn't see anything promising there.

As I read more about cron I'm beginning to wonder if it is the best tool for this job as well.
User avatar
smurphos
Level 18
Level 18
Posts: 8501
Joined: Fri Sep 05, 2014 12:18 am
Location: Irish Brit in Portugal
Contact:

Re: Looking for a hack to change appearance over time.

Post by smurphos »

Bruce McL wrote: Thu Aug 15, 2019 10:17 pm Those commands work - sort of. After I issue the commands in the terminal, I can open up the Settings app and see that the settings have changed. However, I have to log out and log back in to see the changes take effect.
That's weird - changes are immediately apparent on my system. What Mint version are you using?
For custom Nemo actions, useful scripts for the Cinnamon desktop, and Cinnamox themes visit my Github pages.
Bruce McL

Re: Looking for a hack to change appearance over time.

Post by Bruce McL »

smurphos wrote: Fri Aug 16, 2019 1:52 am
Bruce McL wrote: Thu Aug 15, 2019 10:17 pm Those commands work - sort of. After I issue the commands in the terminal, I can open up the Settings app and see that the settings have changed. However, I have to log out and log back in to see the changes take effect.
That's weird - changes are immediately apparent on my system. What Mint version are you using?
I’m using LMDE 3. I did some more testing. It’s an intermittent problem. Sometimes the changes work in real life, and sometimes only in the preferences. The theme name command seems to have the most problems.

I could probably write something in BASIC, but not in BASH :-). Here is an algorithm I would start with.

The day is divided into six segments, each with their own color of appearance themes.
The first task is to determine which segment we are in now from the current time.

On Startup or wake from sleep:
Get the time in hours 0-24
Add 2, divide by 4, truncate to 1 digit.
Store the result as “Segment” (this will have integer values of 0-6)
Go to part [value of Segment] in Endless loop.
End Startup

Endless loop:
part 0
if themes are not red then set themes to red
wait until 02:00
part 1
if themes are not purple then set themes to purple
wait until 06:00
part 2
if themes are not aqua then set themes to aqua
wait until 10:00
part 3
if themes are not green then set themes to green
wait until 14:00
part 4
if themes are not sand then set themes to sand
wait until 18:00
part 5
if themes are not orange then set themes to orange
wait until 22:00
lpart 6
go to part 0
End Endless loop

I don’t have to worry about entering the loop in the middle of a segment because I’m waiting until a specific time of day for the next color change, not counting down 4 hours.
If the user puts their laptop to sleep for a few minutes the colors will often stay the same. Therefore it is not necessary to write the preferences on wake or startup every time. The gsettings command does have the ability to return the current theme.
User avatar
smurphos
Level 18
Level 18
Posts: 8501
Joined: Fri Sep 05, 2014 12:18 am
Location: Irish Brit in Portugal
Contact:

Re: Looking for a hack to change appearance over time.

Post by smurphos »

smurphos wrote: Thu Aug 15, 2019 1:45 am Give me a day or three...
Here you go - this should work.

Save the script below in the folder ~/.local/bin with a sensible name and make it executable. Create the folder if it doesn't exist.

e.g. ~/.local/bin/theme-by-time.sh

Code: Select all

#!/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)
# 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 1000 ]; then
    THEME_CHOICE=Mint-Y-Dark-Aqua
    NEXT_TIME=1000
  elif [ "$CURRENT_TIME" -ge 1000 ] && [ "$CURRENT_TIME" -lt 1400 ]; then
    THEME_CHOICE=Mint-Y-Dark
    NEXT_TIME=1400
  elif [ "$CURRENT_TIME" -ge 1400 ] && [ "$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-Red
    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 until NEXT_TIME
  sleep $(($(date -d "$NEXT_TIME" +%s) - $(date -d "$CURRENT_TIME" +%s)))
done
Then create an entry in Startup applications to run it or just drop this Startup desktop file into ~/.config/autostart

e.g. ~/.config/autostart/theme-by-time.desktop

Code: Select all

[Desktop Entry]
Type=Application
Exec=theme-by-time.sh
X-GNOME-Autostart-enabled=true
NoDisplay=false
Hidden=false
Name=theme-by-time
Comment=No description
X-GNOME-Autostart-Delay=10
Log off and log back on.
For custom Nemo actions, useful scripts for the Cinnamon desktop, and Cinnamox themes visit my Github pages.
Bruce McL

Re: Looking for a hack to change appearance over time.

Post by Bruce McL »

smurphos wrote: Sat Aug 17, 2019 2:43 am
smurphos wrote: Thu Aug 15, 2019 1:45 am Give me a day or three...
Here you go - this should work.
Thank you! I will test this out over the next few days.
Bruce McL

Re: Looking for a hack to change appearance over time.

Post by Bruce McL »

Bruce McL wrote: Sat Aug 17, 2019 1:11 pm
smurphos wrote: Sat Aug 17, 2019 2:43 am Here you go - this should work.
Thank you! I will test this out over the next few days.
It works! Thank you for making it, this is fun to use. I have been able to modify the code to rearrange the schedule and the colors. That part I am able to follow. I have a question about one other part of the code.

Code: Select all

# Kill if already running
if pidof -o %PPID -x "${0##*/}"; then
  exit 1
fi
I think I understand what this does, but I would like to make a change and I don't know how. Instead of exiting from the newly started process, I would like to terminate the previously existing process and continue on with the new one. This would give a reset of the themes based on the current time.

This script is called up on wake from sleep. If the computer has slept through a scheduled theme change, I want the script to update the theme based on the current time instead of exiting.

I have a workaround in place, but I think changing the code above would be simpler.

Thanks again for your help. -Bruce.
User avatar
smurphos
Level 18
Level 18
Posts: 8501
Joined: Fri Sep 05, 2014 12:18 am
Location: Irish Brit in Portugal
Contact:

Re: Looking for a hack to change appearance over time.

Post by smurphos »

Bruce McL wrote: Sun Aug 18, 2019 9:52 am I think I understand what this does, but I would like to make a change and I don't know how. Instead of exiting from the newly started process, I would like to terminate the previously existing process and continue on with the new one. This would give a reset of the themes based on the current time.
Sure - I hadn't considered suspends and hibernates and to be honest until I just tested wasn't 100% sure of the effect on a script with a long sleep, but suspends will knock the timing out of whack.

So replace that code block with this one

Code: Select all

# Kill any existing instances
for PIDS in $(pidof -o %PPID -x "${0##*/}"); do
  if [ "$PIDS" != $$ ]; then
    kill -9 "$PIDS"
  fi 
done
Also see https://unix.stackexchange.com/question ... emd-wakeup for running the script automatically on wakeup from suspend using a systemd service.
For custom Nemo actions, useful scripts for the Cinnamon desktop, and Cinnamox themes visit my Github pages.
Bruce McL

Re: Looking for a hack to change appearance over time.

Post by Bruce McL »

smurphos wrote: Sun Aug 18, 2019 2:41 pm So replace that code block with this one
That's much better! Thanks for the link as well, I'll post back if I get the wake from sleep part working.
Bruce McL

Re: Looking for a hack to change appearance over time.

Post by Bruce McL »

Running theme-by-time.sh script on wake from sleep:

Calling theme-by-time.sh from a file located in /lib/systemd/system-sleep/ does not work, because the environment is different. Basically the user's theme settings are not visible to theme-by-time.sh when it is initiated from that location.

Making a systemd service did not work for me. I don't know why. It may be for a similar reason.

Perhaps there is a way to specify the desired environment in the script (or service) that calls theme-by-time.sh, so that theme-by-time.sh runs in the environment it expects, and finds the appropriate settings to modify. I don't know enough to know if that is possible or reasonable.

For perspective here, we are looking at the edge case where the computer is sleeping when the time for a new theme color passes. Other than that everything works as it should. If the user notices that their theme did not change colors as expected, they have several options. They can run the script, click on the desktop icon, or log out and log back in.
User avatar
smurphos
Level 18
Level 18
Posts: 8501
Joined: Fri Sep 05, 2014 12:18 am
Location: Irish Brit in Portugal
Contact:

Re: Looking for a hack to change appearance over time.

Post by smurphos »

I haven't got time right now, but I'll see if I can get the systemd service working my end and will update with instructions assuming I'm successful.

It was the answer starting as below that at a glance looked to be the correct approach.
This answer is based on askubuntu.com/a/661747/394818 (as also referred to in the comment by @sun-bear), askubuntu.com/q/616272/394818 and superuser.com/a/1269158/585953.

Using a system service:
For custom Nemo actions, useful scripts for the Cinnamon desktop, and Cinnamox themes visit my Github pages.
User avatar
Moem
Level 22
Level 22
Posts: 16224
Joined: Tue Nov 17, 2015 9:14 am
Location: The Netherlands
Contact:

Re: Looking for a hack to change appearance over time.

Post by Moem »

Bruce McL wrote: Thu Aug 15, 2019 5:22 pm I did some searching online and found an app called Gnome Schedule. It’s a graphical front end for cron. Unfortunately it’s not in the LMDE repositories.
Soooo this thread is about LMDE? I'll move it to the suitable forum section then. LMDE =/= main edition.
Image

If your issue is solved, kindly indicate that by editing the first post in the topic, and adding [SOLVED] to the title. Thanks!
Bruce McL

Re: Looking for a hack to change appearance over time.

Post by Bruce McL »

Moem wrote: Mon Aug 19, 2019 2:21 am
Bruce McL wrote: Thu Aug 15, 2019 5:22 pm I did some searching online and found an app called Gnome Schedule. It’s a graphical front end for cron. Unfortunately it’s not in the LMDE repositories.
Soooo this thread is about LMDE? I'll move it to the suitable forum section then. LMDE =/= main edition.
This thread is about making a daily schedule for theme changes in Cinnamon. My original title of the thread did not describe the subject very well, so I changed it just now. The solution is a script which works in Linux Mint Cinnamon and LMDE. Hopefully the script will work in any distribution that uses Cinnamon.
Locked

Return to “Other Topics & Open Discussion”