Created
April 2, 2016 19:17
-
-
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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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