New: Suspend script for laptops

This commit is contained in:
Akemi Izuko 2023-12-23 20:14:10 -07:00
parent 77d353583c
commit e64d367d18
Signed by: akemi
GPG key ID: 8DE0764E1809E9FC
4 changed files with 36 additions and 1 deletions

View file

@ -6,7 +6,7 @@ if ! command -v ddcutil &>/dev/null && command -v light &>/dev/null; then
lvl="$(light -G)" lvl="$(light -G)"
(swaylock; light -S "$lvl") & (swaylock; light -S "$lvl") &
light -S 3 light -S 1
elif command -v ddcutil &>/dev/null; then elif command -v ddcutil &>/dev/null; then
lvl="$(ddcutil getvcp 10 | awk '{ lvl="$(ddcutil getvcp 10 | awk '{
gsub(" ",""); # Remove spaces gsub(" ",""); # Remove spaces

View file

@ -429,6 +429,8 @@ bindswitch --reload --locked lid:on exec \
bindswitch --reload --locked lid:off exec \ bindswitch --reload --locked lid:off exec \
swaymsg output $laptop dpms on swaymsg output $laptop dpms on
exec swayidle -w timeout 1200 '~/.config/sway/suspend_system.sh'
#bindswitch --reload --locked lid:on exec swaymsg output $laptop_screen disable #bindswitch --reload --locked lid:on exec swaymsg output $laptop_screen disable
#bindswitch --reload --locked lid:on exec '[ $(swaymsg -t get_outputs | grep name | wc -l) == 1 ] && ($sleep) || ($notify "Clamshell mode" "Laptop screen off" && swaymsg output $laptop_screen disable)' #bindswitch --reload --locked lid:on exec '[ $(swaymsg -t get_outputs | grep name | wc -l) == 1 ] && ($sleep) || ($notify "Clamshell mode" "Laptop screen off" && swaymsg output $laptop_screen disable)'

6
sway/suspend_system.sh Executable file
View file

@ -0,0 +1,6 @@
#!/usr/bin/env bash
if [[ "$(cat /proc/acpi/button/lid/LID0/state | awk '{print $2}')" == closed ]]
then
sudo /usr/local/bin/send_sleep_email.sh
systemctl suspend
fi

View file

@ -0,0 +1,27 @@
#!/usr/bin/env bash
declare -r TFILE="$(mktemp)"
cat <<EMAIL > "$TFILE"
From: Systemd-chan <systemd@mami2.moe>
To: Emiliko Mirror <emiliko@mami2.moe>
Subject: Sleep triggered on $(hostname)
Date: $(date)
Dear Emiliko,
$(hostname) went to sleep @ $(date)
============================== Battery ==============================
$(battery_status.sh)
=====================================================================
yours (truly),
Systemd
EMAIL
curl --silent --ssl-reqd \
--url 'smtps://smtp.gmail.com:465' \
--user 'systemd%40mami2.moe:app_password_here' \
--mail-from 'systemd@mami2.moe' \
--mail-rcpt 'emiliko@mami2.moe' \
--upload-file "$TFILE"