Skip to content

Instantly share code, notes, and snippets.

@sming
Last active March 25, 2025 03:16
Show Gist options
  • Save sming/8204721f0063bf8c937dcede32139f65 to your computer and use it in GitHub Desktop.
Save sming/8204721f0063bf8c937dcede32139f65 to your computer and use it in GitHub Desktop.
Dead-simple M[1-N] MacOS shell script that makes a second attempt to start scrcpy as for me, the first attempt nearly always fails. For Raycast but works as standalone.
#!/bin/bash
# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title scrcpy
# @raycast.mode inline
# Optional parameters:
# @raycast.icon 🤖
# @raycast.packageName org.psk.raycast
# Documentation:
# @raycast.description run scrcpy
# @raycast.author Peter Kingswell
# @raycast.authorURL https://github.com/sming
export PATH=/opt/homebrew/bin:$PATH # just in case scrcpy is not on $PATH
echo "scrcpy-ing..."
scrcpy --no-audio --stay-awake --screen-off-timeout=240 --capture-orientation 0 # --stay-awake only applies when plugged in, and don't rotate it else shit gets weird
retVal=$?
# If this one didn't work, which is often, then try again
if [ $retVal -ne 0 ]; then
echo "Retrying - restarting adb server..."
adb kill-server && adb start-server
echo "...server restarted, making attempt #2"
scrcpy --no-audio --stay-awake --screen-off-timeout=240 --capture-orientation 0
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment