Skip to content

Instantly share code, notes, and snippets.

@tylerlmz1
Created November 17, 2019 09:46
Show Gist options
  • Save tylerlmz1/50aabca2bc7ef919a72e61d755cc2c3c to your computer and use it in GitHub Desktop.
Save tylerlmz1/50aabca2bc7ef919a72e61d755cc2c3c to your computer and use it in GitHub Desktop.
paste current time into active window, works in linux
dateString=$(date +"%Y-%m-%d")
timeString=$(date +"%H:%M:%S")
content="-- [ $dateString ] [ $timeString ] --"
# Preserve the current value of the clipboard
clipboard=$(xsel -b -o)
# Put text in primary buffer for Shift+Insert pasting
echo -n "$content" | xsel -p -i
# Put text in clipboard selection for apps like Firefox that
# insist on using the clipboard for all pasting
echo -n "$content" | xsel -b -i
# Paste text into current active window
sleep 0.3
xdotool key shift+Insert
# Restore the original value of the clipboard
sleep 0.5
echo $clipboard | xsel -b -i
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment