[SOLVED] A way to schedule Cinnamon theme changes

Questions about other topics & discussing non-support related topics related to LMDE 3.
Forum rules
Before you post please read how to get help
User avatar
Moem
Level 19
Level 19
Posts: 9201
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 » Mon Aug 19, 2019 12:17 pm

Bruce McL wrote:
Mon Aug 19, 2019 12:04 pm
My original title of the thread did not describe the subject very well, so I changed it just now.
Well done, that should help people find it.
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
Level 1
Level 1
Posts: 46
Joined: Mon Nov 09, 2009 2:25 pm

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

Post by Bruce McL » Mon Aug 19, 2019 12:27 pm

smurphos wrote:
Mon Aug 19, 2019 2:08 am
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:
Those links are helpful. I can see one mistake I made in setting up my systemd service. I will try again and report back.

Bruce McL
Level 1
Level 1
Posts: 46
Joined: Mon Nov 09, 2009 2:25 pm

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

Post by Bruce McL » Mon Aug 19, 2019 7:15 pm

smurphos wrote:
Sun Aug 18, 2019 2:41 pm
Also see https://unix.stackexchange.com/question ... emd-wakeup for running the script automatically on wakeup from suspend using a systemd service.
The example .service file in the second answer of the link you provided looks like it should work. I followed the directions: uncommented the user and environment lines and change the user value to my username. However I have not been able to get it to work. I can register and start the theme-by-time.service successfully, but I can’t get it to run the theme-by-time script on wake from sleep.

If I register and start the theme-by-time.service file using the systemctrl --user option the .service file will immediately call the script and change the theme, which is what it’s supposed to do. The --user mode doesn’t understand the references to suspend.target, etc. so it runs the script immediately.

So I made some progress, but I’m not sure where to go from here.

User avatar
smurphos
Level 12
Level 12
Posts: 4086
Joined: Fri Sep 05, 2014 12:18 am
Location: Britisher
Contact:

Re: Looking for a way to schedule Cinnamon theme changes

Post by smurphos » Tue Aug 20, 2019 2:33 am

OK a slightly different approach that avoids the long sleeps and the need to worry about the effect of suspend / resume. As written the script wakes every 60 seconds to quickly check the CURRENT_TIME against the NEXT_TIME. If NEXT_TIME is in the future it will go back to sleep. If not it will apply the correct theme for the CURRENT_TIME, and then go back to sleep.

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)
  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 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
  sleep 60
done
For custom Nemo actions, useful scripts for the Cinnamon desktop, and Cinnamox themes visit my Github pages.

Bruce McL
Level 1
Level 1
Posts: 46
Joined: Mon Nov 09, 2009 2:25 pm

Re: Looking for a way to schedule Cinnamon theme changes

Post by Bruce McL » Tue Aug 20, 2019 2:19 pm

smurphos wrote:
Tue Aug 20, 2019 2:33 am
OK a slightly different approach that avoids the long sleeps and the need to worry about the effect of suspend / resume.
That script looks like a winner! It passes all of my tests.

Edit: For those who are interested, here are the installation instructions:

Copy and paste the code into a text file.
Save it as theme-by-time.sh
Put the file in ~/.local/bin/
Make the file executable.
with this terminal command:

Code: Select all

chmod +x ~/.local/bin/theme-by-time.sh
or, in file manager right click on the file icon > select Properties > select Permissions tab > put a checkmark in the Execute box.

To make the script run at startup, go to System Preferences: Startup Items.
Click the + sign and fill in the blanks
Name: Theme by Time
Command: /home/[your username]/.local/bin/theme-by-time.sh
or, click on the browse button, navigate to ~/.local/bin/ and select the script
Description: changes theme colors during the day
Startup Delay: 0
To activate the script, log out, restart, or in file manager double click on theme-by-time.sh.

Notes:

Adding the startup item will create a theme-by-time desktop file in ~/.config/autostart/

If you want to change the schedule times, be sure to change all three places in the script where the time is specified. Do not change the 2359 end time or the 0000 start time.

Post Reply

Return to “Other Topics & Open Discussion”