Skip to content

Instantly share code, notes, and snippets.

@osfunapps
Last active June 3, 2024 15:22
Show Gist options
  • Save osfunapps/bf5ced177302e13fd2a2fa387773b7fd to your computer and use it in GitHub Desktop.
Save osfunapps/bf5ced177302e13fd2a2fa387773b7fd to your computer and use it in GitHub Desktop.
Just connect your device and run this command, it will connect until a fully steady connection achieved
# removefrom quarantine:
# sudo xattr -rd com.apple.quarantine "/Users/home/Programming/Python/projects/ToolBoxPy/src/linux/connectPhone.command"
# This small script meant to save Apple users the hassle of resetting/disconnecting and connecting an Apple device, again and again, until a steady connection.
# Just connect your device and run this command, it will reconnect the device until a steady connection
# set here the sensitivity of the checks. I fount it best to use these props
MAX_PASSED_CHECKS=50
TIMEOUT_BETWEEN_CHECKS=0.3 # in secs
TIMEOUT_AFTER_EACH_USB_RESET=4 # in secs
# dynamic variables
CHECKS_PASSED=0
# start the checks
while true
do
if [ $CHECKS_PASSED == $MAX_PASSED_CHECKS ]
then
echo "Device connected!"
break
fi
echo "---------------------------------------------"
echo "**** Checking start..."
CHECK_DEVICES_COMMAND=$(system_profiler SPUSBDataType | grep -e iPad -e iPhone)
printf "**** Checking done...\n\n"
if [ -z "$CHECK_DEVICES_COMMAND" ]
then
echo "couldn't find device. Resetting USB..."
CHECKS_PASSED=0
sudo launchctl stop com.apple.usbd; sudo launchctl start com.apple.usbd
echo "Waiting a bit and starting again"
sleep $TIMEOUT_AFTER_EACH_USB_RESET
else
echo "device found! +1 to checks!"
CHECKS_PASSED=$((CHECKS_PASSED+1))
fi
echo "Number of checks passed: $CHECKS_PASSED/$MAX_PASSED_CHECKS"
sleep $TIMEOUT_BETWEEN_CHECKS
done
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment