The morning-alarm.sh script has been modified with the following changes: - Added the 'break' statement after killing the mpv process to exit the loop when the alarm is dismissed. This prevents unnecessary iterations and improves script efficiency. - Commented out the line 'killall /data/data/com.termux/files/usr/bin/mpv' since it seems to be redundant after the 'killall mpv' command. If this line is intended for different use, it may need further clarification or context. These changes enhance the morning-alarm.sh script by optimizing the loop's termination when the alarm is dismissed, improving script efficiency and preventing unnecessary iterations. The redundant 'killall' line has been commented out for clarification.
59 lines
1.6 KiB
Bash
Executable File
59 lines
1.6 KiB
Bash
Executable File
#!/data/data/com.termux/files/usr/bin/zsh
|
|
#
|
|
# Alarm Control Script
|
|
#
|
|
# This script controls the alarm on the Android device.
|
|
# It turns off Bluetooth, increases the volume, and checks if the alarm has been dismissed.
|
|
# After the alarm is dismissed, it plays the alarm sound.
|
|
|
|
echo "Script executed at: $(date)" > /data/scripts/morning-alarm.log
|
|
|
|
# Function to turn off Bluetooth
|
|
turn_off_bluetooth() {
|
|
echo "Turning off Bluetooth."
|
|
svc bluetooth disable || { echo "Error turning off Bluetooth." ; exit 1; }
|
|
}
|
|
|
|
# Function to increase the volume
|
|
increase_volume() {
|
|
echo "Increasing volume."
|
|
cmd media_session volume --set 15 --stream 9 || { echo "Error increasing volume." ; exit 1; }
|
|
}
|
|
|
|
# Function to check the alarm notification
|
|
check_notification() {
|
|
# Run the dumpsys command within a timeout
|
|
output=$(timeout 5s dumpsys activity processes | grep "com.urbandroid.sleep/")
|
|
|
|
# Check if the result is not empty and contains the alarm
|
|
if [ -n "$output" ] && echo "$output" | grep -q "AlarmKlaxon"; then
|
|
date && echo "Alarm not dismissed yet."
|
|
else
|
|
date && echo "Alarm dismissed."
|
|
killall mpv
|
|
break
|
|
#killall /data/data/com.termux/files/usr/bin/mpv
|
|
echo "$output"
|
|
exit
|
|
fi
|
|
}
|
|
|
|
# Main program
|
|
|
|
# Turn off Bluetooth
|
|
turn_off_bluetooth
|
|
|
|
# Increase volume and check notification
|
|
while true; do
|
|
increase_volume
|
|
check_notification
|
|
done &
|
|
|
|
## Play alarm sound
|
|
for ((volume = 20; volume <= 100; volume += 10)); do
|
|
echo "Actual volume: $volume"
|
|
/data/data/com.termux/files/usr/bin/mpv --replaygain=track --volume="$volume" /data/scripts/your-new-morning-alarm.ogg
|
|
#check_notification &
|
|
done
|
|
|