Last active
August 29, 2015 14:21
-
-
Save SuzanaK/2493a54678424b57f758 to your computer and use it in GitHub Desktop.
script to automatically google error messages printed to STDERR, using firefox
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
usage="\nWill google the error message from COMMAND, using Firefox. | |
\nUsage: COMMAND |& $0 \n or COMMAND 2>&1 >/dev/null | $0 (to silence STDIN) \n or $0 ERROR_MESSAGE" | |
if [ "$*" ] ; then | |
input="$*" | |
else | |
read -t0.2 -d'' -r input | |
fi | |
# replace all whitespace with simple spaces | |
input=${input//[[:space:]]/ } | |
if [ -z "$input" ] ; then | |
echo -e $usage | |
exit 0 | |
fi | |
wid=`xdotool search --onlyvisible --name "Mozilla Firefox" | head -1` | |
if [ "$wid" = "" ] ; then | |
exec firefox & | |
sleep 3s | |
fi | |
wid=`xdotool search --onlyvisible --name "Mozilla Firefox" | head -1` | |
actual=`xdotool getactivewindow` | |
if [ $wid != $actual ]; then | |
xdotool windowactivate $wid | |
fi | |
# google arguments | |
xdotool key ctrl+t | |
xdotool key ctrl+j | |
xdotool type "$input" | |
xdotool key Return | |
echo "Finished googling the following error message:" | |
echo -e $input | |
exit 0 |
Known Issue: xdotool won't type special characters like "Umlaute" (ä, ö, ü) that may be contained in the error message.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Will use an existing firefox window to open a new tab or start a new firefox window, and search the error message in the default search engine. Requires xdotool.