From 119bf89bcd06ad02538eb9c1c46a38eb751c4ee4 Mon Sep 17 00:00:00 2001 From: Akemi Izuko Date: Sat, 18 Feb 2023 22:44:12 -0700 Subject: [PATCH] New: Suspend script for laptops --- sway/brightness_lock.sh | 2 +- sway/config | 2 ++ sway/suspend_system.sh | 6 ++++++ sway/template.send_sleep_email.sh | 27 +++++++++++++++++++++++++++ 4 files changed, 36 insertions(+), 1 deletion(-) create mode 100755 sway/suspend_system.sh create mode 100644 sway/template.send_sleep_email.sh diff --git a/sway/brightness_lock.sh b/sway/brightness_lock.sh index fece529..acb7b91 100755 --- a/sway/brightness_lock.sh +++ b/sway/brightness_lock.sh @@ -6,7 +6,7 @@ if ! command -v ddcutil &>/dev/null && command -v light &>/dev/null; then lvl="$(light -G)" (swaylock; light -S "$lvl") & - light -S 3 + light -S 1 elif command -v ddcutil &>/dev/null; then lvl="$(ddcutil getvcp 10 | awk '{ gsub(" ",""); # Remove spaces diff --git a/sway/config b/sway/config index 32335bf..39dc4f5 100644 --- a/sway/config +++ b/sway/config @@ -429,6 +429,8 @@ bindswitch --reload --locked lid:on exec \ bindswitch --reload --locked lid:off exec \ 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 -t get_outputs | grep name | wc -l) == 1 ] && ($sleep) || ($notify "Clamshell mode" "Laptop screen off" && swaymsg output $laptop_screen disable)' diff --git a/sway/suspend_system.sh b/sway/suspend_system.sh new file mode 100755 index 0000000..275d6aa --- /dev/null +++ b/sway/suspend_system.sh @@ -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 diff --git a/sway/template.send_sleep_email.sh b/sway/template.send_sleep_email.sh new file mode 100644 index 0000000..edec65c --- /dev/null +++ b/sway/template.send_sleep_email.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash +declare -r TFILE="$(mktemp)" + +cat < "$TFILE" +From: Systemd-chan +To: Emiliko Mirror +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"