I'm working on a bash script that runs in an infinite 1 second loop, where if it detects that the computer is plugged into AC power, it plays the file
ogg123, and if it is not plugged in, it plays a silent file
Silence.ogg. However, I have a few issues. First, it seems to no longer loop (probably a side effect of the
wait I had to throw in in order to avoid a looping charger input sound after the first detection. Secondly, it doesn't seem to want to change to the
/ directory and it therefore (I'm not sure if due to the
/ error or something else) can't find the files to play. Please help fix this, thanks!
#!/bin/bash "cd /" while true do if on_ac_power; then "ogg123 plugin.ogg" ## Laptop on power else "ogg123 Silence.ogg" ## Laptop on battery fi sleep 10 ## wait 10 sec before repeating done
Terminal output if run while computer is unplugged:
/home/brenden_mcfarling_live/Desktop/ac0.sh: line 3: cd /: No such
file or directory
/home/brenden_mcfarling_live/Desktop/ac0.sh: line 10: ogg123
Silence.ogg: command not found
Terminal output when run while plugged in:
/home/brenden_mcfarling_live/Desktop/ac0.sh: line 3: cd /: No such file or directory
/home/brenden_mcfarling_live/Desktop/ac0.sh: line 8: ogg123 plugin.ogg: command not found
Any help would be appreciated!