TheRepoClub-DotFiles/localbin/.local/bin/audiolock
2021-12-31 05:21:12 +00:00

61 lines
1.8 KiB
Bash
Executable File

#!/usr/bin/env bash
#------------------------------------------------------------------------------
# Path - /usr/bin/audiolock
# GitHub - https://github.com/The-Repo-Club/
# Author - The-Repo-Club [wayne6324@gmail.com]
# Start On - Mon 08 Nov 19:03:28 GMT 2021
# Modified On - Mon 08 Nov 21:30:20 GMT 2021
#------------------------------------------------------------------------------
if ! command -v audiolock &> /dev/null; then
echo "audiolock could not be found"
else
for pid in $(pgrep -f audiolock); do
if [ $pid != $$ ]; then
echo "[$(date)] : audiolock : Process is already running with PID $pid"
exit 1
else
echo "Running with PID $pid"
fi
done
fi
# -/-/-/-/- Settings -/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/
: "${LOCK_SLEEP_VALUE:=5}" # raise this if you experience problems
: "${LOCK_FILE:=/proc/asound/card*/pcm*p/sub*/status}"
: "${TEMP_LOCK_FILE:=/tmp/asound}"
# -/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/
autolock=0
while true ; do
cat $LOCK_FILE > $TEMP_LOCK_FILE
number=0
while IFS= read -r Line; do
if [[ $Line == *"RUNNING"* ]]; then
printf "%s\n" "$Line"
(( number++ ))
break
fi
done < "$TEMP_LOCK_FILE"
printf "%s\n" "${number}"
if [[ $number -eq 0 ]]; then
if [[ $autolock -eq 0 ]]; then
xautolock -enable && notify-send -t 2400 "xautolock" "enabled"
autolock=1
fi
else
if [[ $autolock -eq 1 ]]; then
xautolock -disable && notify-send -t 2400 "xautolock" "disabled"
autolock=0
fi
fi
interval=${LOCK_SLEEP_VALUE:-$(( 10 * 60 ))}
printf 'Sleeping for %s seconds...\n' "$interval"
sleep "$interval"
done