Skip to content

Instantly share code, notes, and snippets.

@ctcherry
Created August 22, 2015 23:14
Show Gist options
  • Save ctcherry/52f7f06df13ba3369f4a to your computer and use it in GitHub Desktop.
Save ctcherry/52f7f06df13ba3369f4a to your computer and use it in GitHub Desktop.
#!/bin/bash
echo "running"
KEY="$(echo -n $(cat ~/.screenshot_uploader.secret))"
HOST="s8t.us"
SFILE="$(find /Users/USER/Desktop -mtime -5s -type f -name 'Screen Shot*' | head -1)"
if [[ -n "$SFILE" ]]; then
TS="$(date +%s)"
SIG=$(echo -n $(echo -n "$TS" | openssl dgst -sha1 -hmac "$KEY"))
SHORTF=${SFILE##*/}
$(curl -F file=@"$SFILE" -F ts=$TS -F sig=$SIG http://$HOST/upload | pbcopy; osascript -e "display notification \"$SHORTF uploaded\" with title \"Screenshot\"" &)
fi
COUNTER=0
while [ $COUNTER -lt 30 ]; do
sleep 2
SFILE="$(find /Users/USER/Desktop -mtime -2s -type f -name 'Screen Shot*' | head -1)"
if [[ -n "$SFILE" ]]; then
TS="$(date +%s)"
SIG=$(echo -n $(echo -n "$TS" | openssl dgst -sha1 -hmac "$KEY"))
SHORTF=${SFILE##*/}
$(curl -F file=@"$SFILE" -F ts=$TS -F sig=$SIG http://$HOST/upload | pbcopy; osascript -e "display notification \"$SHORTF uploaded\" with title \"Screenshot\"" &)
fi
let COUNTER=COUNTER+1
done
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>screenshot upload listener</string>
<key>ProgramArguments</key>
<array>
<string>/Users/USER/bin/screenshot_uploader</string>
<string>path modified</string>
</array>
<key>WatchPaths</key>
<array>
<string>/Users/USER/Desktop/</string>
</array>
</dict>
</plist>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment