Using computer as an alarm clock

Recently I looked at KAlarm, which is very nice for local alarms.

So I have a nice alarm set to wake us up gently 15 minutes before we must rise.

I have ‘Pink Floyd’ to tell my son it’s time to get ready his wonderful Thai Education…

The first issue I had, if he’s watching a cartoon in plexmediaplayer, that would continue playing on wakeup… so I included a small script to kill plexmediaplayer and to reset volume to a ‘sane’ value for wakeup time:

commands () {
date +"It's now %R" | cowthink
echo "How long until suspending?" # e.g. 1h 23m  45s
read TIME;  echo $TIME set!

sudo rtcwake -m no -l -t $(date +%s -d 'tomorrow 0616') # -l localtime, -t time
sudo rtcwake -m show -lv | grep alarm:

sleep $TIME && amixer set Master 45% && systemctl suspend

export -f commands
konsole -e "bash -c 'commands'"

So this will work, as long as the terminal is put away and another app (maybe plex-htpc, or plexmediaplayer, or something else) is at the forefront. The idea is to put away any ‘noisy’ windows before suspend (after we woke up to hear plex resuming a rather noisy cartoon yesterday).

I would preferto just close all windows…
xdotool search --maxdepth 1 "" windowkill %@ goes way too far and the session is logged out.

It isn’t so trivial to grab all ‘windows’ either because that includes stuff like Latte, and Plasma.

Any ideas? Would there be a way to restore a plasma session without logging in? or a good method for killing all windows except those listed in the plasma session?

qdbus org.kde.ksmserver /KSMServer org.kde.KSMServerInterface.sessionList
saved by user

I think that closing all application windows might be possible with a Kwin script; looking at the Github repository I saw there is a minimise all script included with Kwin. I guess this could probably be modified to close all windows instead? The API documentation seems to include close window functions.

@summrum i was thinking same thing. I mean theres the little button on the panel usually that lets you minimize all windows you have up but leaves your widgets and other more permanent things up. It would just that same command (whatever it is) with the alarm clock whitelisted and using the local time as an input instead of a keypress? Which makes me wonder, how would you go about finding out what command that button is using.?

I guess that only the variables set by the windows requiring window decorations (you can see the variables using a tool like xprop for example) are processed by Kwin for minimise.

So step 1 is to enable a simple click to check the RTC wakeup… This does require sudo with PASSWORD.

So first I created a .zsh_personal file for entering any command containing my password.

alias zshconfig='kate ~/.zshrc &'
alias zshalias='kate ~/.config/zsh/.zsh-personal'

First an alias

alias rtccheck=echo Wakeup : && echo PASSWORD | sudo -S rtcwake -m show -l -v |rg alarm: | cut -c 8-30 

This gives me

Wakeup time check:
❯ rtccheck
Wakeup time check:
  Wed Jul 27 06:00:00

Next, a file which does this:

echo PASSWORD | sudo -S rtcwake -m no -l -t $(date +%s -d 'tomorrow 0600')

Which we throw into the scheduler:

And we click ‘run now’ to see how it goes…
and check with ‘rtccheck’

Finally, we can set morning alarms with Kalarm to play something gentle, increasing volume

Kalarm is good for this, when holidays come it’s easy to add exceptions.

As for the sleep timer, I added a check for rtcwake and settled for a single active window kill, and bound this to a keyboard shortcut Ctrl_Sleep.


commands () {
echo Wakeup time check: && echo PASSWORD | sudo -S rtcwake -m show -l -v |rg alarm:
sleep 1;
date +"It's now %R" | cowthink
echo "How long until suspending?"
read TIME
 echo $TIME set!; sleep $TIME;
xdotool getwindowfocus windowkill; amixer set Master 45%; systemctl suspend

export -f commands

konsole -e "bash -c 'commands'"

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.