From feafe252dca372b79bff8fbb594e55435c17359a Mon Sep 17 00:00:00 2001 From: Jeena Date: Sat, 11 Apr 2026 14:41:24 +0000 Subject: [PATCH] Add systemd timers to auto-mute/unmute when idle-inhibit is active Mutes audio at 21:00 and unmutes at 07:00, but only when the idle-inhibit toggle is active (PID file exists). This is useful for leaving the computer running overnight for SSH access while keeping it quiet for sleeping. --- README.md | 11 +++++++++++ systemd/user/auto-mute.service | 7 +++++++ systemd/user/auto-mute.timer | 9 +++++++++ systemd/user/auto-unmute.service | 7 +++++++ systemd/user/auto-unmute.timer | 9 +++++++++ 5 files changed, 43 insertions(+) create mode 100644 systemd/user/auto-mute.service create mode 100644 systemd/user/auto-mute.timer create mode 100644 systemd/user/auto-unmute.service create mode 100644 systemd/user/auto-unmute.timer diff --git a/README.md b/README.md index a4014db..770f5b8 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,17 @@ ln -s ~/Projects/hypr-dotfiles/kitty kitty ln -s ~/Projects/hypr-dotfiles/helix helix ``` +To enable the auto-mute/unmute timers (mutes at 21:00, unmutes at +07:00, only when idle-inhibit is active), link the systemd user units: + +``` +systemctl --user link ~/Projects/hypr-dotfiles/systemd/user/auto-mute.service +systemctl --user link ~/Projects/hypr-dotfiles/systemd/user/auto-mute.timer +systemctl --user link ~/Projects/hypr-dotfiles/systemd/user/auto-unmute.service +systemctl --user link ~/Projects/hypr-dotfiles/systemd/user/auto-unmute.timer +systemctl --user enable --now auto-mute.timer auto-unmute.timer +``` + You also need to install all the dependencies: - hyprland diff --git a/systemd/user/auto-mute.service b/systemd/user/auto-mute.service new file mode 100644 index 0000000..811b7b4 --- /dev/null +++ b/systemd/user/auto-mute.service @@ -0,0 +1,7 @@ +[Unit] +Description=Mute audio when idle-inhibit is active + +[Service] +Type=oneshot +ExecCondition=/bin/bash -c 'test -f ${XDG_RUNTIME_DIR}/idle-inhibit.pid && kill -0 $(cat ${XDG_RUNTIME_DIR}/idle-inhibit.pid)' +ExecStart=/usr/bin/wpctl set-mute @DEFAULT_AUDIO_SINK@ 1 diff --git a/systemd/user/auto-mute.timer b/systemd/user/auto-mute.timer new file mode 100644 index 0000000..ddcd649 --- /dev/null +++ b/systemd/user/auto-mute.timer @@ -0,0 +1,9 @@ +[Unit] +Description=Mute audio at 21:00 + +[Timer] +OnCalendar=*-*-* 21:00:00 +Persistent=false + +[Install] +WantedBy=timers.target diff --git a/systemd/user/auto-unmute.service b/systemd/user/auto-unmute.service new file mode 100644 index 0000000..c00d1a0 --- /dev/null +++ b/systemd/user/auto-unmute.service @@ -0,0 +1,7 @@ +[Unit] +Description=Unmute audio when idle-inhibit is active + +[Service] +Type=oneshot +ExecCondition=/bin/bash -c 'test -f ${XDG_RUNTIME_DIR}/idle-inhibit.pid && kill -0 $(cat ${XDG_RUNTIME_DIR}/idle-inhibit.pid)' +ExecStart=/usr/bin/wpctl set-mute @DEFAULT_AUDIO_SINK@ 0 diff --git a/systemd/user/auto-unmute.timer b/systemd/user/auto-unmute.timer new file mode 100644 index 0000000..e0a57c5 --- /dev/null +++ b/systemd/user/auto-unmute.timer @@ -0,0 +1,9 @@ +[Unit] +Description=Unmute audio at 07:00 + +[Timer] +OnCalendar=*-*-* 07:00:00 +Persistent=false + +[Install] +WantedBy=timers.target