I am writing a script which uses hot corners to play specific musical notes when hovering in corners, and depending on the musical sequence to execute a specific command.
The script is called with parameter -d from bottom left, -e from b-right, -g from top-left, -b from top-right, appends the sequence in a file (~/bin/for_hot) and compares the sequence with my associative array. Plays a succesful musical B'' when the sequence is recognized.
2 issues:
Sometimes the commands won't execute, even though the succesful sound plays;
I don't manage to poweroff. [SOLVED]
I think I am not monitoring the processes adequately afterwards (kill, background), and also the file (~/bin/for_hot) I am appending may not be written to in time.
Here is the script, please note I am a noob in linux so don't hate my code, my question, me too much:
#!/bin/bash
#switch###############################
case "$1" in
-d) play -q -n synth 3 pluck 293.665 &
sleep 0.5
echo -n "d" >> ~/bin/for_hot;
;;
-e) play -q -n synth 3 pluck 311.127 &
sleep 0.5
echo -n "e" >> ~/bin/for_hot;
;;
-g) play -q -n synth 3 pluck 391.995 &
sleep 0.5
echo -n "g" >> ~/bin/for_hot;
;;
-b) play -q -n synth 3 pluck 466.164 &
sleep 0.5
echo -n "b" >> ~/bin/for_hot;
;;
esac
######################################
#midi mappings########################
declare -A commands
commands=(
["egbd"]="firefox -n"
["ebgb"]="idea"
["ebb"]="notify-send "$instr ""
["egdgb"]="echo pass | sudo -S poweroff"
["ee"]="nemo /home/mintbwoy");
######################################
s=$(<~/bin/for_hot);
for pattern in "${!commands[@]}";
do
echo "$pattern - ${commands["$pattern"]}";
if [[ "$s" == *"$pattern"* ]]
then
echo -n "" > ~/bin/for_hot;
play -q -n synth 3 pluck 932.328 &
var=$(${commands["$s"]});
$var;
notify-send "[$pattern] = ${commands["$pattern"]} "$var"";
fi
done
######################################
sudo
with shutdown : http://askubuntu.com/a/454077/295286 – Sergiy Kolodyazhnyy May 03 '16 at 11:43eval "$var" "&"
, but that's not a 100% correct syntax. I'm on mobile and don't remember it off the top of my head – Sergiy Kolodyazhnyy May 03 '16 at 12:55