分享一个手机截屏脚本

前提条件是电脑上已经配置好adb,那么可以用./screenshot.sh或者双击capture.bat直接使用截屏功能

screenshot.sh:

#!/bin/sh
#version 1.0

#set -x
#set -v

device_locate=`adb devices | egrep "device" | wc -l`
if [ $device_locate != "1" ];then
notify-send "Connect error OR More than one device"
exit
fi

deviceID=`adb devices | egrep "device" | cut -f 1`
echo $deviceID

flag=`adb shell ls /system/bin/ | grep "screencap" | wc -l`
if [ $flag != "1" ];then
notify-send "Current device not support"
exit
fi

adb shell mkdir /sdcard/screenshot
echo "Capturing screenshot..."
adb shell /system/bin/screencap -p /sdcard/screenshot/test.png

filename="screenshot"+`date`+".png"
date=`date '+%y%m%d'`
datetime=`date '+%y%m%d%H%M%S'`
user=`whoami`
pc_path="/home/$user/screenshot"
echo "Pulling screenshot to computer..."
echo "user: $user"
echo "path:$pc_path"

[ -d $pc_path/$date ] || mkdir $pc_path/$date
adb pull /sdcard/screenshot/test.png $pc_path/$date/
tmp="$pc_path/$date"
mv $tmp/test.png $tmp/${deviceID}_${datetime}.png
if [ -e $tmp ];then
notify-send "Capture Successfully,path:$tmp"
else
notify-send "Capture failed,device not support or device not found"
fi
#set -x
#set -v

capture.bat:

adb shell screencap -p /sdcard/1.png
set s=screenshot
set y=%date:~0,4%%date:~5,2%%date:~8,2%
set h=%time:~0,2%%time:~3,2%%time:~6,2%
set var=%s%_%y%_%h%
md E:Screenshots\%y%
echo "Capturing screenshot..."
adb pull /sdcard/1.png E:Screenshots\%y%\%var%.png
echo "Successfully!!!"

原文地址:https://www.cnblogs.com/mgzc-1508873480/p/7405377.html