Created
December 8, 2022 02:10
-
-
Save lincerely/65a3e1c77a14be846fe4cb9367c753a9 to your computer and use it in GitHub Desktop.
run command when mac clipboard change
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 | |
| # pbwatch - run cmd when clipboard change | |
| tmp=/tmp/clipboard | |
| cmd=${@:1} | |
| if [ -z "$cmd" ]; then | |
| echo "USAGE: $0 CMD [ARGS...]" | |
| exit 1 | |
| fi | |
| process() { | |
| pbpaste > $tmp | |
| /usr/bin/env bash -c "$cmd" | |
| } | |
| while sleep 1; do | |
| if [ -f $tmp ]; then | |
| diff=`diff -q $tmp <(pbpaste) | wc -l` | |
| if [ $diff -eq 1 ]; then | |
| process | |
| fi | |
| else | |
| process | |
| fi | |
| done |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example, read clipboard content on change:
pbwatch "pbpaste | say"