Skip to content

Instantly share code, notes, and snippets.

@zenny
Forked from naelstrof/seen.sh
Created October 26, 2015 08:24
Show Gist options
  • Save zenny/6a6c7a4ac2165c28772a to your computer and use it in GitHub Desktop.
Save zenny/6a6c7a4ac2165c28772a to your computer and use it in GitHub Desktop.
Takes screenshots and videos of user selection, automatically uploads to a server mounted on your system, then copies the URL to your clipboard.Depends on xclip, ffmpeg, maim, mplayer, and slop.Use "seen.sh image" to capture an image, and use "seen.sh video" to start recording a video. Then use "seen.sh video" again to stop recording.I use maim …
#!/bin/bash
server="/mnt/charles/farmstore/content/${1}s"
url="http://farmpolice.com/content/${1}s"
imageEncoding=".png"
videoEncoding=".webm"
imagetake="/usr/share/sounds/freedesktop/stereo/screen-capture.oga"
videotake="/usr/share/sounds/freedesktop/stereo/complete.oga"
name=$(cat /dev/urandom | tr -cd 'a-f0-9' | head -c 8)
pidFile="/tmp/seen_record.pid"
# Purple for images
slopcmdimage="slop -b 5 -c 0.3,0.1,0.6 --nodecorations"
# Pink for videos
slopcmdvideo="slop -b 5 -c 0.6,0.1,0.3 --nodecorations"
case "$1" in
image)
eval $(${slopcmdimage})
if [ "${Cancel}" = "true" ]; then
exit 0
fi
maim -g $G "${server}/${name}${imageEncoding}"
echo -n "${url}/${name}${imageEncoding}" | xclip -selection clipboard
mplayer "${imagetake}"
;;
video)
# If we're already recording, kill ffmpeg and exit. Thus ending the recording.
if [ -f "${pidFile}" ]; then
pid=$(cat "${pidFile}")
kill ${pid}
# Play a sound for some feedback indicating the video recording ended.
mplayer "${videotake}"
exit 0
fi
eval $(${slopcmdvideo})
if [ "${Cancel}" = "true" ]; then
exit 0
fi
# We start recording and then immediately record the PID for later with a fancy bash constant "$!".
ffmpeg -f x11grab -s "${W}x${H}" -i ":0.0+${X},${Y}" -f alsa -i pulse "${server}/${name}${videoEncoding}" &
pid=$!
echo -n "$pid" > /tmp/seen_record.pid
echo -n "${url}/${name}${videoEncoding}" | xclip -selection clipboard
;;
*)
echo "Usage: $0 {image|video}"
exit 1
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment