You are not logged in.
Hello!
Sometimes I have my notebook working through the night and thus I want it to not go into hibernation or standby. But I still want the screen to turn off, so it's LEDs don't lose lifetiem, the image doesn't burn it and on top waste energy.
I don't want to have to manually do a 'sudo ..' whatever for changing the configuration each time. It should be a single click action, like by using an XFCE app starter icon.
Using presentation mode from the tray menu obviously disables ALL services, like screensaver, screen idle, and auto hibernation/standby at once, so this isn't a solution, too.
Are there ways for doing this easily and reliably? The only way I know how this possibly could work would be by starting a script which has password-less sudo allowance for whatever commands needed to achieve this, to then show a window with a text, toggling in between enabled / disabled. But this neither is very elegant nor secure, I assume - if I even can make it work.
Thank you for help! ![]()
Last edited by Elmario (2026-01-05 17:06:05)
Offline
OK: I finally am done with a script for solving this issue. Comments are in German, but I think it's easy to understand and modify, in case someone likes to use it.
The script cycles through three different modes:
Normal, Film and Nightwork.
In Normal mode standby and display power are both enabled, with configurable timeout.
In Film mode simply the presentation mode is enabled, thus it won't break a movie watching experience. So there's no timeout for either the system or the displays.
In Nightwork only the screen gets switched off using dpms after a configurable timeout, so the PC can stay working on a problem without wasting energy on the display and decreasing the display's lifespan.
The notifications have been enhanced by adding some images and sounds from the Chicago95 themes, which I am using for my desktop. Of course these can be changed to any other sound and image files, too.
The script is primarily made for being run by a button in the quick launch area, but it can be run from a terminal, too. In case of terminal usage two parameters are supported:
-t for not only showing notifications when switching the profile, but also outputting info to stdout.
-g for just getting the current mode instead of switching to the next one
#!/usr/bin/env bash
# set -euo pipefail:
# -e: Abbruch bei Fehler (wir sichern xfconf-Befehle mit || true ab)
# -u: Abbruch bei ungesetzten Variablen
# -o pipefail: Fehler in Pipes werden erkannt
set -euo pipefail
# --------------------------------------------------
# KONFIGURATION
# --------------------------------------------------
NOTIFY_TIME=5000
SND_DIR="$HOME/.local/share/sounds/Chicago95/stereo"
SOUND_NORMAL="$SND_DIR/bell-window-system.wav"
SOUND_NACHT="$SND_DIR/file-trash.wav"
SOUND_FILM="$SND_DIR/desktop-logout.wav"
SOUND_ERROR="$SND_DIR/dialog-warning.wav"
# Zeitwerte in MINUTEN
MON_NORMAL=25
SYS_NORMAL=60
MON_NACHT=5
SYS_NACHT=0
CHANNEL="xfce4-power-manager"
PROP_SLEEP="/xfce4-power-manager/inactivity-sleep-mode-on-ac"
PROP_INACTIVITY="/xfce4-power-manager/inactivity-on-ac"
PROP_DPMS_TIMER="/xfce4-power-manager/dpms-on-ac-off"
PROP_DPMS_ENABLED="/xfce4-power-manager/dpms-enabled"
PROP_PRESENTATION="/xfce4-power-manager/presentation-mode"
STATE_FILE="/tmp/nightmode.state"
INHIBIT_PID_FILE="/tmp/nightmode.inhibit.pid"
SHOW_TERMINAL=false
JUST_SHOW=false
# --------------------------------------------------
# OPTIONEN PARSEN
# --------------------------------------------------
while getopts ":tg" opt; do
case "$opt" in
t) SHOW_TERMINAL=true ;;
g) JUST_SHOW=true ;;
*) exit 1 ;;
esac
done
# --------------------------------------------------
# HILFSFUNKTIONEN
# --------------------------------------------------
cleanup_runtime_artifacts() {
if [[ -f "$INHIBIT_PID_FILE" ]]; then
local pid
pid=$(cat "$INHIBIT_PID_FILE" 2>/dev/null || echo "")
if [[ -n "$pid" && "$pid" =~ ^[0-9]+$ ]]; then
if ! kill -0 "$pid" 2>/dev/null; then
rm -f "$INHIBIT_PID_FILE"
fi
else
rm -f "$INHIBIT_PID_FILE"
fi
fi
}
start_inhibitor() {
if [[ -f "$INHIBIT_PID_FILE" ]]; then return; fi
systemd-inhibit \
--what=sleep:idle \
--who="toggle_nightmode" \
--why="Nachtarbeitsmodus aktiv" \
--mode=block \
sleep infinity & echo $! > "$INHIBIT_PID_FILE"
}
stop_inhibitor() {
if [[ -f "$INHIBIT_PID_FILE" ]]; then
local pid
pid=$(cat "$INHIBIT_PID_FILE" 2>/dev/null || echo "")
if [[ -n "$pid" && "$pid" =~ ^[0-9]+$ ]]; then
kill "$pid" 2>/dev/null || true
fi
rm -f "$INHIBIT_PID_FILE"
fi
}
set_xfce_prop() {
local prop="$1" value="$2" type="${3:-int}"
xfconf-query -c "$CHANNEL" -p "$prop" -n -t "$type" -s "$value" 2>/dev/null || true
}
apply_state() {
case "$1" in
NORMAL)
stop_inhibitor
set_xfce_prop "$PROP_PRESENTATION" "false" "bool"
set_xfce_prop "$PROP_DPMS_ENABLED" "true" "bool"
set_xfce_prop "$PROP_DPMS_TIMER" "$MON_NORMAL"
set_xfce_prop "$PROP_SLEEP" "2" # Hibernate
set_xfce_prop "$PROP_INACTIVITY" "$SYS_NORMAL"
;;
NACHT)
start_inhibitor
set_xfce_prop "$PROP_PRESENTATION" "false" "bool"
set_xfce_prop "$PROP_DPMS_ENABLED" "true" "bool"
set_xfce_prop "$PROP_DPMS_TIMER" "$MON_NACHT"
set_xfce_prop "$PROP_SLEEP" "0" # Aus
set_xfce_prop "$PROP_INACTIVITY" "0"
;;
FILM)
stop_inhibitor
set_xfce_prop "$PROP_PRESENTATION" "true" "bool"
;;
esac
}
# --------------------------------------------------
# LOGIK
# --------------------------------------------------
cleanup_runtime_artifacts
CURRENT_STATE=$(cat "$STATE_FILE" 2>/dev/null || echo "NORMAL")
if [[ "$JUST_SHOW" != true ]]; then
case "$CURRENT_STATE" in
NORMAL) NEXT_STATE="NACHT" ;;
NACHT) NEXT_STATE="FILM" ;;
FILM) NEXT_STATE="NORMAL" ;;
*) NEXT_STATE="NORMAL" ;;
esac
apply_state "$NEXT_STATE"
echo "$NEXT_STATE" > "$STATE_FILE"
else
NEXT_STATE="$CURRENT_STATE"
fi
# --------------------------------------------------
# FEEDBACK DEFINIEREN
# --------------------------------------------------
case "$NEXT_STATE" in
NORMAL)
TITLE="NORMAL-MODUS"
ICON="computer"
TEXT="Monitor: ${MON_NORMAL}m, Hibernate: ${SYS_NORMAL}m"
SOUND="$SOUND_NORMAL"
CUR_MON="$MON_NORMAL"
CUR_SYS="$SYS_NORMAL"
;;
NACHT)
TITLE="NACHTARBEITS-MODUS"
ICON="sleep"
TEXT="Monitor: ${MON_NACHT}m, System: IMMER AN"
SOUND="$SOUND_NACHT"
CUR_MON="$MON_NACHT"
CUR_SYS="0 (Immer an)"
;;
FILM)
TITLE="FILM-MODUS"
ICON="dragonplayer"
TEXT="Präsentationsmodus: Alles dauerhaft an"
SOUND="$SOUND_FILM"
CUR_MON="0 (Unendlich)"
CUR_SYS="0 (Immer an)"
;;
*)
TITLE="FEHLER"
ICON="dialog-warning"
TEXT="Status unbekannt"
SOUND="$SOUND_ERROR"
CUR_MON="?"
CUR_SYS="?"
;;
esac
# --------------------------------------------------
# FEEDBACK AUSFÜHREN
# --------------------------------------------------
# 1. Benachrichtigung
notify-send -t "$NOTIFY_TIME" -i "$ICON" "$TITLE" "$TEXT" 2>/dev/null || true
# 2. Sound abspielen
if [[ -f "$SOUND" ]]; then
paplay "$SOUND" &
elif [[ "$SHOW_TERMINAL" == true ]]; then
echo "Hinweis: Sounddatei nicht gefunden: $SOUND"
fi
# 3. Terminal Ausgabe (nur bei -t)
if [[ "$SHOW_TERMINAL" == true ]]; then
echo "=========================================="
echo " AKTIVIERTER MODUS: $NEXT_STATE"
echo "------------------------------------------"
echo " Aktueller Monitor-Timeout: $CUR_MON Min"
echo " Aktueller System-Timeout: $CUR_SYS Min"
echo " Inhibitor-Prozess (Sleep): $([[ -f "$INHIBIT_PID_FILE" ]] && echo "AKTIV" || echo "aus")"
echo " Präsentationsmodus: $(xfconf-query -c "$CHANNEL" -p "$PROP_PRESENTATION" 2>/dev/null || echo "n/a")"
echo "=========================================="
fiLast edited by Elmario (2026-01-05 17:10:40)
Offline