Skip to content

Instantly share code, notes, and snippets.

@mbjd
Created April 2, 2016 19:17
Show Gist options
  • Save mbjd/3223206b9241a3d9bb14a573f61f639a to your computer and use it in GitHub Desktop.
Save mbjd/3223206b9241a3d9bb14a573f61f639a to your computer and use it in GitHub Desktop.
Print clipboard changes to stdout with timestamp and new content. Works only on OS X (or wherever you have something equivalent to `pbpaste` installed).
#!/usr/bin/env bash
# Tracks contents of the clipboard by printing changes to
# stdout with a timestamp
last=$(pbpaste)
# Check if the clipboard content has changed, and if it has
# output the new contents with a timestamp
sample() {
current=$(pbpaste)
if [ "$current" != "$last" ]; then
printf "$(date -u +"%Y-%m-%d %H:%M:%S"): \"$current\"\n";
last=$current;
fi
}
# Print the clipboard at the start
printf "Started tracking\n"
printf "$(date -u +"%Y-%m-%d %H:%M:%S"): \"$(pbpaste)\"\n"
# Main loop, checks for changes each second
while true; do
sample;
sleep 1;
done;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment