Androidのスクリーンショットを撮るスクリプト


複数端末(エミュレータ含む)から選びつつ、スクリーンショットを撮って、画像を開くまでやってくれる君。(adb導入済み前提)

接続端末が1つなら、その接続端末のスクリーンショットを撮ってくれる。

#!/bin/zsh

adb_devices_result=`adb devices | sed -e '1,1d'`
echo $adb_devices_result | while read line
do
    line_elements=(`echo ${line}`)
    devices+=($line_elements[1])
done

if [ $#devices[*] -eq 0 ]; then
    echo "ERROR: No connected devices."
    exit
elif [ $#devices[*] -eq 1 ]; then
    target_device=$devices[1]
else
    echo "Choose a device..."
    select target_device in $devices
    do
        if [ -z $target_device ]; then
            continue
        else
            break
        fi
    done
fi

echo "Now taking a screenshot..."

filename=`date +"%Y%m%d-%H%M%S"`$DATETIME.png
adb -s $target_device shell screencap /sdcard/$filename
adb -s $target_device pull /sdcard/$filename $TMPDIR
adb -s $target_device shell rm /sdcard/$filename
open $TMPDIR/$filename

echo "Done."

参考

コマンドラインからAndroidのスクリーンショットをPCデスクトップに取得する方法