Skip to content

Instantly share code, notes, and snippets.

@Ghedeon
Last active June 26, 2020 05:26
Show Gist options
  • Save Ghedeon/6969116ca08c530d41c137a8310d9e60 to your computer and use it in GitHub Desktop.
Save Ghedeon/6969116ca08c530d41c137a8310d9e60 to your computer and use it in GitHub Desktop.
Screenshot & Recorder

1. Screenshot

Description (no more than one connected device):

  1. Sets device in demo mode: hides your notifications, fixed clock, full battery, wifi level)
  2. Takes a screenshot and saves it into captures directory. Also to your clipboard, so it's ready for Paste
  3. Exits demo mode

Usage:

  1. Download screenshot.sh
  2. chmod +x screenshot.sh
  3. Optional, MacOS: Automator → New Quck Action → Run Shell Script Insert:
    
      export PATH="your env PATH"
      cd ~/dev/scripts
      ./screenshot.sh
     
    Add it to your TouchBar (add Quick Actions group) or assign a global hot key Keyboard → Shortcuts → Service → Screenshot

2. GIF/MP4 recorder

Dependencies: brew install ffmpeg

Description:

  1. Sets device in demo mode
  2. Starts recording and awaits for Ctrl + C
  3. MP4 clip is downloaded and removed from device, gif encoded and saved to captures
  4. Exits demo mode

Usage:

  1. Download recorder.sh
  2. chmod +x recorder.sh
  3. Optional, MacOS, iTerm: Automator → New Quck Action → AppleScript Insert:

  on run {input, parameters}
	
	tell application "iTerm"
		activate
		tell current window
			create tab with default profile
		end tell
		
		tell first session of current tab of current window
			write text "cd ~/dev/scripts&&./recorder.sh"
			--write text "./recorder.sh"
		end tell
		
	end tell
	
	return input
end run

Add it to your TouchBar (add Quick Actions group) or assign a global hot key Keyboard → Shortcuts → Service → Recorder

#!/bin/sh
# Example:
# ./recorder.sh
# ./recorder.sh feature
function ctrl_C() {
echo -e "\nRecording Finished"
echo "Downloading screenrecord"
sleep 2
adb pull /sdcard/Movies/${CLIP_FILE} ${CLIP_PATH} >/dev/null
adb shell rm /sdcard/Movies/${CLIP_FILE}
echo ${CLIP_PATH}
echo "Making gif"
gifify >/dev/null
rm ${CLIP_PATH}
echo ${GIF_PATH}
}
function enterDemoMode() {
adb shell settings put global sysui_demo_allowed 1 >/dev/null
adb shell am broadcast -a com.android.systemui.demo -e command network -e wifi show -e level 4 >/dev/null
adb shell am broadcast -a com.android.systemui.demo -e command network -e mobile show -e datatype none -e level 4 >/dev/null
adb shell am broadcast -a com.android.systemui.demo -e command battery -e level 100 -e plugged false >/dev/null
adb shell am broadcast -a com.android.systemui.demo -e command clock -e hhmm 0440 >/dev/null
adb shell am broadcast -a com.android.systemui.demo -e command notifications -e visible false >/dev/null
adb shell content insert --uri content://settings/system --bind name:s:show_touches --bind value:i:1
echo "Recording Started"
echo "Press CTRL-C to stop"
}
function exitDemoMode() {
adb shell am broadcast -a com.android.systemui.demo -e command exit >/dev/null
adb shell content insert --uri content://settings/system --bind name:s:show_touches --bind value:i:0
openResult
}
function openResult() {
case "$OSTYPE" in
linux*) xdg-open ${GIF_PATH} ;;
darwin*) open -R ${GIF_PATH} ;;
esac
}
function gifify(){
palette="/tmp/palette.png"
filters="fps=25,scale=360:-1:flags=lanczos"
ffmpeg -v warning -i ${CLIP_PATH} -vf "$filters,palettegen" -y ${palette} >/dev/null
ffmpeg -v warning -i ${CLIP_PATH} -i ${palette} -lavfi "$filters [x]; [x][1:v] paletteuse" -y ${GIF_PATH} >/dev/null
}
mkdir -p captures
if [[ -z "$1" ]]; then
FILE=$(date +%Y-%m-%d-%H-%M-%S)
else
FILE="$*"
fi
CLIP_FILE=${FILE}.mp4
CLIP_PATH=captures/${CLIP_FILE}
GIF_PATH=captures/${FILE}.gif
enterDemoMode
trap ctrl_C INT
trap exitDemoMode EXIT
adb shell screenrecord --bit-rate 6000000 /sdcard/Movies/${CLIP_FILE}
#!/bin/sh
# Example:
# ./screenshot.sh
# ./screenshot.sh feature
function enterDemoMode() {
adb shell settings put global sysui_demo_allowed 1
adb shell am broadcast -a com.android.systemui.demo -e command network -e wifi show -e level 4
adb shell am broadcast -a com.android.systemui.demo -e command network -e mobile show -e datatype none -e level 4
adb shell am broadcast -a com.android.systemui.demo -e command battery -e level 100 -e plugged false
adb shell am broadcast -a com.android.systemui.demo -e command clock -e hhmm 0440
adb shell am broadcast -a com.android.systemui.demo -e command notifications -e visible false
}
function exitDemoMode() {
adb shell am broadcast -a com.android.systemui.demo -e command exit >/dev/null
echo ${SCREENSHOT_PATH}
clip_img ${SCREENSHOT_PATH}
openResult
}
function clip_img() {
osascript -e 'on run argv' \
-e 'set currentDir to do shell script "pwd"' \
-e 'set the clipboard to (read POSIX file (POSIX path of (currentDir as text & (first item of argv) )) as JPEG picture)' \
-e 'end run' "/$1"
}
function openResult() {
case "$OSTYPE" in
linux*) xdg-open ${SCREENSHOT_PATH} ;;
darwin*) open -R ${SCREENSHOT_PATH} ;;
esac
}
mkdir -p captures
if [[ -z "$1" ]]; then
SCREENSHOT_PATH=captures/$(date +%Y-%m-%d-%H-%M-%S).png
else
SCREENSHOT_PATH=captures/"$*".png
fi
enterDemoMode >/dev/null
trap exitDemoMode EXIT
adb exec-out screencap -p > ${SCREENSHOT_PATH}
echo $PATH
#convert -resize 360 ${SCREENSHOT_PATH} ${SCREENSHOT_PATH} >/dev/null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment