From 7d7a3108ddc7621d5e16b45d25e1587c25301fd6 Mon Sep 17 00:00:00 2001 From: Storm Dragon Date: Mon, 14 Nov 2022 08:07:30 -0500 Subject: [PATCH] Moved the sequence storm reader to a more generic clipboard_reader.sh script. There very well could be bugs, so please report if you find them. --- audiogame-manager.sh | 58 +------------------------------------- speech/clipboard_reader.sh | 44 +++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 57 deletions(-) create mode 100755 speech/clipboard_reader.sh diff --git a/audiogame-manager.sh b/audiogame-manager.sh index 54a7927..1bb6f29 100755 --- a/audiogame-manager.sh +++ b/audiogame-manager.sh @@ -130,62 +130,6 @@ desktop_launcher() { exit 0 } -# Create the clipboard reading function for Sequence Storm -write_sequence_storm_reader() { -if -e ~/.SequenceStormReader ]]; then - return - fi -# Here-document start -cat << "EOF" > ~/.SequenceStormReader -#!/usr/bin/env bash - -# Wait for the game to be launched -while ! pgrep -u "$USER" ^SequenceStorm &> /dev/null ; do - sleep 0.05 -done - -export DISPLAY=:0 -unset cliptext -socketFile="$(find /tmp -maxdepth 1 -name "orca-*.sock")" -while pgrep -u "$USER" ^SequenceStorm &> /dev/null ; do - if [[ "$(uname)" == "Darwin" ]]; then - tmp="$(pbpaste 2> /dev/null)" - else - tmp="$(xclip -selection clipboard -o 2> /dev/null)" - fi - tmp="${tmp//%/ percent }" - if [ "$tmp" != "$cliptext" ] ; then - cliptext="$tmp" - if [[ "${cliptext,,}" =~ key|load|private|says|terminal ]]; then - if [[ "$(uname)" == "Darwin" ]]; then - say -v alex -r 300 "$cliptext" - else - if [[ -w "${socketFile}" ]]; then - echo "<#APPEND#>$cliptext" | socat - UNIX-CLIENT:"${socketFile}" - else - spd-say -w -r 50 -- "$cliptext" - fi - fi - else - if [[ "$(uname)" == "Darwin" ]]; then - say -v alex -r 300 "$cliptext" - else - if [[ -w "${socketFile}" ]]; then - echo "$cliptext" | socat - UNIX-CLIENT:"${socketFile}" - else - spd-say -r 50 -- "$cliptext" - fi - fi - fi - fi - sleep 0.05 -done - -exit 0 -EOF -# Here-document end - chmod 755 ~/.SequenceStormReader -} # Wine configuration section @@ -821,7 +765,7 @@ game_launcher() { "${0%/*}/speech/speak_window_title.sh" trtr.exe & fi if [[ "$game" =~ sequence-storm ]]; then - [[ -x ~/.SequenceStormReader ]] && ~/.SequenceStormReader & + "${0%/*}/speech/clipboard_reader.sh" SequenceStorm & fi if [[ "$game" =~ audiodisc ]]; then wine "$winePath\\$wineExec" diff --git a/speech/clipboard_reader.sh b/speech/clipboard_reader.sh new file mode 100755 index 0000000..2ca97a4 --- /dev/null +++ b/speech/clipboard_reader.sh @@ -0,0 +1,44 @@ +#!/usr/bin/env bash + +# Wait for the game to be launched +while ! pgrep -u "$USER" ^$1 &> /dev/null ; do + sleep 0.05 +done + +unset cliptext +socketFile="$(find /tmp -maxdepth 1 -name "orca-*.sock")" +while pgrep -u "$USER" ^$1 &> /dev/null ; do + if [[ "$(uname)" == "Darwin" ]]; then + tmp="$(pbpaste 2> /dev/null)" + else + tmp="$(xclip -d "${DISPLAY:-:0}" -selection clipboard -o 2> /dev/null)" + fi + tmp="${tmp//%/ percent }" + if [ "$tmp" != "$cliptext" ] ; then + cliptext="$tmp" + if [[ "${cliptext,,}" =~ key|load|private|says|terminal ]]; then + if [[ "$(uname)" == "Darwin" ]]; then + say -v alex -r 300 "$cliptext" + else + if [[ -w "${socketFile}" ]]; then + echo "<#APPEND#>$cliptext" | socat - UNIX-CLIENT:"${socketFile}" + else + spd-say -w -r 50 -- "$cliptext" + fi + fi + else + if [[ "$(uname)" == "Darwin" ]]; then + say -v alex -r 300 "$cliptext" + else + if [[ -w "${socketFile}" ]]; then + echo "$cliptext" | socat - UNIX-CLIENT:"${socketFile}" + else + spd-say -r 50 -- "$cliptext" + fi + fi + fi + fi + sleep 0.05 +done + +exit 0