14
13

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

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

Last updated at Posted at 2016-02-03

複数端末(エミュレータ含む)から選びつつ、スクリーンショットを撮って、画像を開くまでやってくれる君。(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デスクトップに取得する方法

14
13
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14
13

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?