#!/bin/sh . $HOME/.shenv # ---- CONFIG ---- MUSIC="$(echo ~/lib/annex/doc/sounds/m*.mp3)" # ---- TASKS THAT SHOULD ALWAYS HAPPEN ---- #movemymail # ---- TASKS THAT SHOULD HAPPEN ONLY IF LID IS CLOSED ---- if grep -q open /proc/acpi/button/lid/LID/state; then exit 0 fi if ! [ -f "$MUSIC" ]; then echo >&2 "no music to play" exit 1 fi # also see # https://github.com/sm-Fifteen/systemd-alarm/blob/master/alarmclock # for how to point all sources at the right sink if that becomes an # issue (e.g. if I habitually leave headphones plugged in) pactl set-sink-mute @DEFAULT_SINK@ 0 pactl set-sink-volume @DEFAULT_SINK@ 100% ffplay "$MUSIC" -loop 0 -nodisp -loglevel quiet & music_pid=$! # TODO ignore the lid's state unless it was closed when this script # started? that would mean this script works on non-laptops too, and # on laptop if I suspend it with its lid open while grep -q closed /proc/acpi/button/lid/LID/state \ && acpi -a | grep -q on-line; do sleep 0.5 done kill $music_pid