Skip to content

Instantly share code, notes, and snippets.

@azenla
Created October 11, 2016 04:17
Show Gist options
  • Save azenla/4c061463f3688222d512741f438c5418 to your computer and use it in GitHub Desktop.
Save azenla/4c061463f3688222d512741f438c5418 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -e
DISCORDS="$(xdotool search "Discord" | tail -n 1)"
CONTENT="$(cat - | sed -r 's/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g' | sed '0~20 a\``````\')"
if [ "${CONTENT: -6}" == '``````' ]
then
CONTENT="${CONTENT::-3}"
fi
if [ -z "${DISCORDS}" ]
then
echo "Discord window was not found."
exit 1
fi
for W in ${DISCORDS}
do
xdotool windowactivate ${W}
xdotool key --window ${W} Tab
xdotool type --window ${W} '```'
xdotool type --window ${W} "${CONTENT}"
[ "${CONTENT: -3}" != '```' ] && xdotool type --window ${W} '```'
xdotool key --window ${W} KP_Enter
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment