Skip to content

Instantly share code, notes, and snippets.

@quietlynn
Created July 6, 2014 15:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save quietlynn/f3b03ebf1d510eec9acb to your computer and use it in GitHub Desktop.
Save quietlynn/f3b03ebf1d510eec9acb to your computer and use it in GitHub Desktop.
Inputting chat message in Minecraft (probably with IM)
#!/bin/bash
# Dependencies:
# * xdotool
# * xclip
# * kdialog or zenity
# * perl (only if "sleep 0.3" (float) is not accepted)
# Usage:
# Bind this script to a keyboard shortcut and then press it in Minecraft.
# Configuration:
paste_sleep=0.3 # Increase if chat is sent too early, before paste is accepted.
dialog_text="Chat:"
# == The script now begins ==
dialog="kdialog --inputbox \"$dialog_text\""
if ! which kdialog; then
if which zenity; then
dialog="zenity --entry --text=\"$dialog_text\""
else
echo "Please install kdialog or zenity."
exit 1
fi
fi
portable_sleep() {
sleep $1 >/dev/null 2>/dev/null || perl -e "select(undef,undef,undef,$1);"
}
xdotool key "t"
eval set -- $dialog
if text=$("$@"); then
echo -n "$text" | xclip -i -selection clipboard
xdotool key "ctrl+v"
portable_sleep $paste_sleep
xdotool key Return
else
xdotool key Escape
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment