Last active
October 28, 2022 09:07
-
-
Save myamamic/a960387397706aba3189c132049a48d8 to your computer and use it in GitHub Desktop.
Do adb command with choosing connected device
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# このスクリプトは他のスクリプトから使われます | |
# | |
# 接続するデバイスのシリアル番号を取得するスクリプト | |
# このスクリプトの標準出力の最後に、選択したデバイスのシリアル番号が出力されます | |
# 使う側は、最後の出力を使ってください | |
BUFIFS=$IFS | |
IFS= | |
# 少なくとも1台端末が接続されるまで待つ | |
adb wait-for-device 1>&/dev/null | |
i=0 | |
CONNECTED_DEVICE_ID= | |
DEVICE_ID_LIST= | |
while read LINE | |
do | |
# タブで区切られている行の第一フィールドのみ抜き出す. ex) 000000001111<\t>device | |
CONNECTED_DEVICE_ID=`echo ${LINE} | cut -s -f 1` | |
# device IDのみ表示する | |
if [ ${CONNECTED_DEVICE_ID} ]; then | |
echo "${CONNECTED_DEVICE_ID} : [${i}]" | |
i=`expr ${i} + 1` | |
DEVICE_ID_LIST=${DEVICE_ID_LIST}$'\n'${CONNECTED_DEVICE_ID} | |
fi | |
done < <(adb devices) | |
echo "Please choose number of target device :" | |
read DEVICE_NUMBER | |
i=0 | |
while read LINE | |
do | |
if [ ${LINE} ]; then | |
# 指定されたデバイス番号なら表示し、出力する | |
if [ ${i} -eq ${DEVICE_NUMBER} ]; then | |
echo "${LINE}" | |
break | |
fi | |
i=`expr ${i} + 1` | |
fi | |
done < <(echo "${DEVICE_ID_LIST}") | |
IFS=$BUFIFS |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# screencap を実行して小さめにリサイズした画像を出力する | |
# このスクリプトのディレクトリパスを取得 | |
SHELL_DIR=`dirname $0` | |
# 接続するデバイスのシリアル番号を取得するスクリプト | |
# このスクリプトの標準出力の最後に、デバイスIDが出力されます | |
source ${SHELL_DIR}/adb-choice-device.sh | tee temp_device_serial_id | |
DEVICE_ID=`tail -n 1 temp_device_serial_id` | |
rm temp_device_serial_id | |
FILE_NAME=screen-`date "+%Y%m%dT%H%M%S"`.png | |
adb -s ${DEVICE_ID} shell screencap -p /sdcard/${FILE_NAME} | |
adb -s ${DEVICE_ID} pull /sdcard/${FILE_NAME} | |
adb -s ${DEVICE_ID} shell rm -f /sdcard/${FILE_NAME} | |
# 縦横比を保ちつつ「縦幅」指定でリサイズ | |
sips --resampleHeight 600 ${FILE_NAME} -o ${FILE_NAME} | |
echo "${FILE_NAME} created" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# screenrecord の mp4 をいい感じの gif にする | |
# このスクリプトのディレクトリパスを取得 | |
SHELL_DIR=`dirname $0` | |
# 接続するデバイスのシリアル番号を取得する | |
source ${SHELL_DIR}/adb-choice-device.sh | tee temp_device_serial_id | |
DEVICE_ID=`tail -n 1 temp_device_serial_id` | |
rm temp_device_serial_id | |
function stopped () { | |
sleep 1 | |
adb -s ${DEVICE_ID} pull /sdcard/record.mp4 | |
ffmpeg -i record.mp4 -loop 0 -final_delay 200 -vf scale=320:-1 -r 12 record.gif | |
echo "record.mp4 and record.gif created" | |
} | |
trap 'stopped' 2 | |
rm -f record.mp4 | |
adb -s ${DEVICE_ID} shell rm -f /sdcard/record.mp4 | |
echo '録画を開始しました。録画を終了する場合は、 Ctrl+C を押下してください' | |
adb -s ${DEVICE_ID} shell screenrecord /sdcard/record.mp4 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# screenrecord を実行する | |
# このスクリプトのディレクトリパスを取得 | |
SHELL_DIR=`dirname $0` | |
# 接続するデバイスのシリアル番号を取得する | |
source ${SHELL_DIR}/adb-choice-device.sh | tee temp_device_serial_id | |
DEVICE_ID=`tail -n 1 temp_device_serial_id` | |
rm temp_device_serial_id | |
function stopped () { | |
sleep 1 | |
adb -s ${DEVICE_ID} pull /sdcard/record.mp4 | |
echo "record.mp4 created" | |
} | |
trap 'stopped' 2 | |
rm -f record.mp4 | |
adb -s ${DEVICE_ID} shell rm -f /sdcard/record.mp4 | |
echo '録画を開始しました。録画を終了する場合は、 Ctrl+C を押下してください' | |
adb -s ${DEVICE_ID} shell screenrecord /sdcard/record.mp4 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# このスクリプトは [scrcpy](https://github.com/Genymobile/scrcpy) がインストールされている環境で動作します | |
# このスクリプトは adb-choice-device.sh と同じディレクトリに置いてください | |
# このスクリプトのディレクトリパスを取得 | |
SHELL_DIR=`dirname $0` | |
# 接続するデバイスのシリアル番号を取得する | |
source ${SHELL_DIR}/adb-choice-device.sh | tee temp_device_serial_id | |
DEVICE_ID=`tail -n 1 temp_device_serial_id` | |
rm temp_device_serial_id | |
function stopped () { | |
sleep 1 | |
echo "stopped" | |
} | |
trap 'stopped' 2 | |
echo 'scrcpy を開始しました。scrcpy を終了する場合は、 Ctrl+C を押下してください' | |
scrcpy -s ${DEVICE_ID} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment