Created
February 15, 2026 04:42
-
-
Save suwardhana/cf5d362437395d748b44cc144190d184 to your computer and use it in GitHub Desktop.
auto launch scrcpy on android device connect
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 | |
| export PATH="/Users/suwardhana/Library/Android/sdk/platform-tools:$PATH" | |
| ADB="/Users/suwardhana/Library/Android/sdk/platform-tools/adb" | |
| SCRCPY="/usr/local/bin/scrcpy" | |
| LOG="/tmp/monitor-android.log" | |
| echo "Starting Android device monitor..." >> "$LOG" | |
| while true; do | |
| DEVICE_COUNT=$($ADB devices | awk '/device$/{count++} END{print count+0}') | |
| SCRCPY_RUNNING=$(pgrep -x scrcpy >/dev/null && echo true || echo false) | |
| if [ "$DEVICE_COUNT" -gt 0 ] && [ "$SCRCPY_RUNNING" = false ]; then | |
| echo "Device connected. Launching scrcpy..." >> "$LOG" | |
| "$SCRCPY" >/dev/null 2>&1 & | |
| elif [ "$DEVICE_COUNT" -eq 0 ] && [ "$SCRCPY_RUNNING" = true ]; then | |
| echo "Device disconnected. Stopping scrcpy..." >> "$LOG" | |
| pkill -x scrcpy | |
| fi | |
| sleep 5 | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment