#!/bin/bash # # xpaste2window - types pasted contents into the then-focused X window # # $Id$ # original by Vincent Huijgen # See also xclip # Note that xclip pastes into the terminal where it is invoked, # ignoring focus changes. So this script, started at window1: # # echo abc | xclip # sleep 5 # and manually move focus to window2 # xclip -o # # will paste "abc" into window1 delay=5 lineout='' prompt='Paste your input, then hit Enter: ' prompt2='To reuse this input, hit Enter, or paste new input, then hit Enter: ' copypasteloop() { while read -s -p "$prompt" linein do echo case "$linein" in '') case "$lineout" in '') echo 'Not pasting an empty line ...' continue ;; esac ;; *) lineout="$linein" ;; esac echo "Focus on an X window; the input will be typed there after $delay seconds..." sleep $delay xdotool type "$lineout" prompt=$prompt2 done } copypasteloop