From 0069c456959b22f2ab0286a1ee4ca928533071c7 Mon Sep 17 00:00:00 2001 From: dataprolet Date: Sat, 25 May 2024 13:33:23 +0000 Subject: [PATCH] Add script by sunrise/sunset --- Scripts/plasma-theme-switcher/themer-sun.sh | 34 +++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Scripts/plasma-theme-switcher/themer-sun.sh diff --git a/Scripts/plasma-theme-switcher/themer-sun.sh b/Scripts/plasma-theme-switcher/themer-sun.sh new file mode 100644 index 0000000..fe5379b --- /dev/null +++ b/Scripts/plasma-theme-switcher/themer-sun.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +# Get your coordinates here: https://www.latlong.net/ +lat=52.520008 +long=13.404954 + +# Get the times for sunrise and sunset +sunrise=$(curl "https://api.sunrisesunset.io/json?lat=$lat&lng=$long" |jq -r '.results | .sunrise') +sunset=$(curl "https://api.sunrisesunset.io/json?lat=$lat&lng=$long" |jq -r '.results | .sunset') + +# Convert them into hours and minutes +hour_sunrise=$(date -d "$sunrise" +"%H") +min_sunrise=$(date -d "$sunrise" +"%M") +hour_sunset=$(date -d "$sunset" +"%H") +min_sunset=$(date -d "$sunset" +"%M") + +# Get the current hour and minute +current_hour=$(date +%H) +current_minute=$(date +%M) + +# Convert current time to minutes since midnight +current_time=$((10#$current_hour * 60 + 10#$current_minute)) + +# Define the start times in minutes since midnight +start_command1=$(($hour_sunset * 60 + $min_sunset)) +end_command1=$(($hour_sunrise * 60 + $min_sunrise)) + +if (( current_time >= start_command1 || current_time < end_command1 )); then + # Execute command1 if the time is between sunset and sunrise + plasma-apply-colorscheme BreezeDark +else + # Execute command2 if the time is between sunrise and sunset + plasma-apply-colorscheme BreezeLight +fi