From c617af1b4081ecd9e3c78535193dca6573f68763 Mon Sep 17 00:00:00 2001 From: Or Bin Date: Fri, 16 Aug 2024 01:55:20 +0300 Subject: [PATCH] Add a sleep reminder notification on personal computer --- configuration/notify_sleep.sh | 12 ++++++++++++ tasks/basic-linux-tools.yml | 1 + tasks/configuration.yml | 16 ++++++++++++++++ 3 files changed, 29 insertions(+) create mode 100755 configuration/notify_sleep.sh diff --git a/configuration/notify_sleep.sh b/configuration/notify_sleep.sh new file mode 100755 index 0000000..823c748 --- /dev/null +++ b/configuration/notify_sleep.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +export DBUS_SESSION_BUS_ADDRESS=${DBUS_SESSION_BUS_ADDRESS:-"unix:path=/run/user/$(id -u)/bus"} + +if [[ "$(gnome-screensaver-command --query)" = "The screensaver is active" ]]; then + echo "Screen is locked, exiting" + exit +fi + +notify-send -t 300000 'Go to sleep!' 'Screen will be locked in 2 minutes' +sleep 120 +gnome-screensaver-command --activate diff --git a/tasks/basic-linux-tools.yml b/tasks/basic-linux-tools.yml index 3aa7170..0e8d724 100644 --- a/tasks/basic-linux-tools.yml +++ b/tasks/basic-linux-tools.yml @@ -20,6 +20,7 @@ - zsh - simplescreenrecorder - dconf-editor + - libnotify-bin become: yes - name: Check if oh-my-zsh is installed diff --git a/tasks/configuration.yml b/tasks/configuration.yml index 0bec2e0..52b1560 100644 --- a/tasks/configuration.yml +++ b/tasks/configuration.yml @@ -50,6 +50,22 @@ file: path: "{{ ansible_user_dir }}/bin" state: directory + register: scripts_dir + +- name: Copy notify_sleep.sh + copy: + src: "{{ playbook_dir }}/configuration/notify_sleep.sh" + dest: "{{ scripts_dir.path }}/notify_sleep.sh" + register: notify_sleep_script + when: computer_type == "personal" + +- name: Add notify_sleep.sh to cron + ansible.builtin.cron: + name: notify_sleep + minute: "*/15" + hour: "0-4" + job: "{{ notify_sleep_script.dest }}" + when: computer_type == "personal" - name: Set ptrace_scope for Go debugging ansible.builtin.replace: