Added script for controlling alarm on Android device

This script turns off Bluetooth, increases the media volume to 100%, and continuously checks if the alarm has been dismissed on the Android device. Additionally, it plays the morning alarm sound in an infinite loop until the alarm is dismissed.

- Script Name: morning-alarm.sh
- Features:
  - Turn off Bluetooth
  - Set media volume to 100%
  - Play the morning alarm sound in an infinite loop
  - Continuously check for alarm dismissal

Author: Michael Haider
Date: 17.12.2023
This commit is contained in:
Ratatoskr 2023-12-17 21:46:44 +01:00
parent b881b79bf6
commit 1dc5643f7b
Signed by: Ratatoskr
GPG Key ID: 28B77439A6D78F4E

47
morning-alarm.sh Executable file
View File

@ -0,0 +1,47 @@
#!/bin/sh
#
# Wecker-Steuerungsskript
#
# Dieses Skript steuert den Wecker auf dem Android-Gerät.
# Es schaltet Bluetooth aus, erhöht die Lautstärke und überprüft, ob der Wecker beendet wurde.
# Nach dem Beenden des Weckers wird der Weckersound abgespielt.
# Funktion zum Ausschalten von Bluetooth
turn_off_bluetooth() {
am broadcast -a android.bluetooth.adapter.action.STATE_CHANGED --ei android.bluetooth.adapter.extra.STATE 10
}
# Funktion zum Erhöhen der Lautstärke
increase_volume() {
cmd media_session volume --set 15 --stream 9
}
# Funktion zum Überprüfen der Weckerbenachrichtigung
check_notification() {
# Führe den dumpsys-befehl innerhalb eines Timeout aus
output=$(timeout 5s dumpsys activity processes | grep com.urbandroid.sleep || echo "Timeout")
# Überprüfe, ob das Ergebnis nicht "Timeout" ist und den Wecker enthält
if [ "$output" != "Timeout" ] && [ "$(echo "$output" | grep "com.urbandroid.sleep/.alarmclock.AlarmKlaxon")" ]; then
date && echo "Wecker noch nicht beendet."
else
date && echo "Wecker beendet."
echo "$output"
exit
fi
}
# Hauptprogramm
# Ausschalten von Bluetooth
turn_off_bluetooth
# Weckersound abspielen
/data/data/com.termux/files/usr/bin/mpv --replaygain=track --loop=inf /product/media/audio/alarms/your-new-morning-alarm.ogg &
# Lautstärke erhöhen und Benachrichtigung überprüfen
while true; do
increase_volume
check_notification
done