summaryrefslogtreecommitdiff
path: root/archive/bin/new_goodmorning
blob: 4e77901a0cddf66f053db887d102b372d1eeab8b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/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