mirror of
https://github.com/The-Repo-Club/DotFiles.git
synced 2024-11-28 18:28:39 -05:00
dc75d84e78
Signed-off-by: The-Repo-Club <wayne6324@gmail.com>
61 lines
1.8 KiB
Bash
Executable File
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 1400 "xautolock" "enabled"
|
|
autolock=1
|
|
fi
|
|
else
|
|
if [[ $autolock -eq 1 ]]; then
|
|
xautolock -disable && notify-send -t 1400 "xautolock" "disabled"
|
|
autolock=0
|
|
fi
|
|
fi
|
|
|
|
interval=${LOCK_SLEEP_VALUE:-$(( 10 * 60 ))}
|
|
printf 'Sleeping for %s seconds...\n' "$interval"
|
|
sleep "$interval"
|
|
done
|