devicectl.sh
1 # Add to your zsh profile 2 3 function devicepid() { 4 if [ -z "$1" ]; then 5 echo "Usage: devicepid <device-name> <search>" 6 echo "Example: devicepid 'iPhone 15 Pro Max' SpringBoard" 7 return 1 8 fi 9 10 if [ -z "$2" ]; then 11 echo "Usage: devicepid <device-name> <search>" 12 echo "Example: devicepid 'iPhone 15 Pro Max' SpringBoard" 13 return 1 14 fi 15 16 xcrun devicectl device info processes --device "$1" | grep "$2" | awk '{ print $1; }' 17 } 18 19 func devicekill() { 20 if [ -z "$1" ]; then 21 echo "Usage: devicekill <device-name> <process-name>" 22 echo "Example: devicekill 'iPhone 15 Pro Max' SpringBoard" 23 return 1 24 fi 25 26 if [ -z "$2" ]; then 27 echo "Usage: devicekill <device-name> <process-name>" 28 echo "Example: devicekill 'iPhone 15 Pro Max' SpringBoard" 29 return 1 30 fi 31 32 TARGETPID=$(devicepid "$1" "$2") 33 34 if [ $? -ne 0 ]; then 35 echo "Couldn't find PID for $2" 36 return 1 37 fi 38 39 echo "Found PID for $2: $TARGETPID" 40 41 xcrun devicectl device process signal --pid $TARGETPID --signal SIGHUP --device "$1" 42 } 43 44 func respring() { 45 if [ -z "$1" ]; then 46 echo "Usage: respring <device-name>" 47 return 1 48 fi 49 50 devicekill "$1" "SpringBoard" 51 } 52 53 func devicereboot() { 54 if [ -z "$1" ]; then 55 echo "Usage: devicereboot <device-name>" 56 return 1 57 fi 58 59 xcrun devicectl device reboot --device "$1" 60 }