The purpose of this script is to simplify the use of scrcpy (a tool for displaying and controlling Android devices from a computer) on macOS by:
- Allowing users to specify a custom resolution or use the default
scrcpysettings. - Automatically retrying
scrcpyexecution on failure with a short delay. - Providing a clean and visually appealing interface with progress bars and prompts.
- Ensuring a clean session by disabling Zsh history and removing cache files on exit.
- Custom Resolution Input: Users can specify a resolution (e.g., 720) for
scrcpy -mor use the default settings. - Automatic Retries: Retries
scrcpyexecution on failure with a 1-second delay. - Progress Bar: Displays a dynamic progress bar during the 60-second timeout for user prompts.
- Session Cleanup: Prevents Zsh history saving and removes cache files (
~/.zsh_history,~/.zcompdump*) on exit or Ctrl+C. - User-Friendly Interface: Clear prompts and a clean layout with colored output for better readability.
- Retry Prompt: After 50 attempts, prompts the user to continue or exit with a 60-second timeout.
- macOS: This script is designed for macOS, as it uses a
.commandfile executable in Terminal.app. - Zsh: The script is written for the Zsh shell, which is the default shell on macOS (since macOS Catalina).
- scrcpy: Must be installed and accessible in the system's PATH (e.g., via Homebrew:
brew install scrcpy). - Android Device: A connected Android device with USB debugging enabled.
- Clone the repository:
git clone https://github.com/your-username/scrcpy-auto-retry.git
- Navigate to the repository directory:
cd scrcpy-auto-retry - Ensure the script is executable:
chmod +x scrcpy-auto-retry.command
The script is packaged as a .command file, which is macOS-specific and can be run in several ways using a Zsh terminal (Terminal.app on macOS):
-
Double-Click to Run:
- Locate the
scrcpy-auto-retry.commandfile in Finder. - Double-click the file to automatically open it in Terminal.app and execute the script.
- Note: If macOS blocks the file (due to security settings), right-click the file, select Open, and confirm to allow execution.
- Locate the
-
Right-Click to Open in Terminal:
- In Finder, right-click the
scrcpy-auto-retry.commandfile. - Select Open With > Terminal (or Terminal.app).
- This will launch the script in a new Terminal window.
- In Finder, right-click the
-
Direct Execution in Terminal: Navigate to the script's directory and run:
./scrcpy-auto-retry.command
-
Absolute Path Execution: Run the script using its full path:
/path/to/scrcpy-auto-retry/scrcpy-auto-retry.command
-
Using Zsh Explicitly: If Zsh is not your default shell, explicitly invoke it:
zsh ./scrcpy-auto-retry.command
-
Running from Any Directory: If the script is in your PATH, you can run it directly:
scrcpy-auto-retry.command
To add it to your PATH, move the script to a directory like
/usr/local/binand ensure it's executable:sudo mv scrcpy-auto-retry.command /usr/local/bin/ sudo chmod +x /usr/local/bin/scrcpy-auto-retry.command
Steps After Launch:
- Enter a resolution for
scrcpy -m(e.g.,720) when prompted, or press Enter to use the default settings. - The script will attempt to run
scrcpy. If it fails, it will retry automatically with a 1-second delay. - After 50 attempts, the script will prompt you to continue (
y) or exit (nor timeout after 60 seconds). - Press
Ctrl+Cat any time to exit cleanly, resetting the terminal and removing cache files.
Below are screenshots demonstrating the script's interface in action:
- The script uses Zsh-specific features (
setopt,read -k, etc.) and is designed to run in a Zsh environment, which is the default on macOS. - Ensure
scrcpyis properly configured and your Android device is connected via USB with debugging enabled. - The script prevents history saving to maintain a clean session, which is useful for privacy or debugging purposes.
- The progress bar and colored output enhance the user experience but require a terminal that supports ANSI escape codes.
- The
.commandfile is macOS-specific and may not work on other operating systems without modification. - If double-clicking the
.commandfile does not work due to macOS security settings, you may need to adjust Gatekeeper settings (System Settings > Privacy & Security) or use the right-click Open method.
This project is licensed under the MIT License. See the LICENSE file for details.

