Skip to content

Instantly share code, notes, and snippets.

@dualfade
Last active May 18, 2023 21:06
Show Gist options
  • Save dualfade/aa654aa6ffa2c650cd41680855043701 to your computer and use it in GitHub Desktop.
Save dualfade/aa654aa6ffa2c650cd41680855043701 to your computer and use it in GitHub Desktop.
#!/bin/bash
# shellcheck disable=SC2059
# simulate_typing.sh
# #dualfade --
# ref --
# tldr xdotool; https://www.mankier.com/1/xdotool --
# tldr xclip; https://linux.die.net/man/1/xclip --
function vdi_clip2win() {
# paste selection --
# ex; copy something; run functions and point to target window --
if [[ -e "$(command -v xdotool)" ]] && [[ -e "$(command -v xclip)" ]] || true; then
echo "[INFO] => paste file to target window"
sleep 3
#NOTE: paste to selected window --
xclip -selection clipboard -out | \
tr \\n \\r | \
xdotool selectwindow windowfocus type --clearmodifiers --delay 25 --window %@ --file -
else
echo "[INFO] Install => xdotool and xclip"
echo "[ERR] Exiting !"
fi
}
function vdi_file2win() {
# read input file --
# ex; cat somefile and pipe to script function; run functions and point to target window --
if [[ -e "$(command -v xdotool)" ]] && [[ -e "$(command -v xclip)" ]] || true; then
echo "[INFO] => readfile to target window"
sleep 3
#NOTE: paste to selected window --
xclip -selection clipboard -in -
#WARN: carriage return; block paste --
tr \\n \\r | \
xdotool selectwindow windowfocus type --clearmodifiers --delay 25 --window %@ --file -
else
# errors --
echo "[INFO] Install => xdotool and xclip"
echo "[ERR] Exiting !"
fi
}
# run it --
# vdi_clip2win
vdi_file2win
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment