#!/bin/bash # Export X display variable (in order for script to have access to desktop) export DISPLAY=:0 # Extract new code from STDIN using awk parser, head and # tail commands for first line in the message body NEW_CODE=$(cat /dev/stdin | awk '/Content-Type: text\/plain;/,G' | head -3 | tail -1) # Extract old code from temp file OLD_CODE=$(cat ~/scripts/old_code) # If, and only if new code is different from the old code # use xdotool to simulate typing it to active window # and store new code in a temp file if [ "$NEW_CODE" != "$OLD_CODE" ] then xdotool getactivewindow type "$NEW_CODE" xdotool key Return echo "$NEW_CODE" > ~/scripts/old_code fi