Skip to content

Instantly share code, notes, and snippets.

@halilozercan
Created March 3, 2020 14:59
Show Gist options
  • Select an option

  • Save halilozercan/e4ac84d5816f367644ecda2aabf51f40 to your computer and use it in GitHub Desktop.

Select an option

Save halilozercan/e4ac84d5816f367644ecda2aabf51f40 to your computer and use it in GitHub Desktop.
# A shell script to launch scrcpy automatically when a device is connected
# Device name selection is based on lines from `adb devices -l`.
# Script takes a single argument to match any of these lines.
# First matched devices' serial number is used for scrcpy device serial number.
while true
do
# Try to start scrcpy
scrcpy -s $(adb devices -l | awk -v j=$1 'index($0, j);' | awk '{print $1}')
# If scrcpy was closed by user, do not restart until device is replugged in.
if [ $? -eq 0 ]; then
while [ $(adb devices -l | awk -v j=$1 'index($0, j);' | wc -l) -gt 0 ]; do
sleep 0.2
done
fi
sleep 1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment