Skip to content

Instantly share code, notes, and snippets.

@insidegui
Created October 19, 2023 21:58
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save insidegui/b570ec998b9e2aeb730f4e142f0593d1 to your computer and use it in GitHub Desktop.
Save insidegui/b570ec998b9e2aeb730f4e142f0593d1 to your computer and use it in GitHub Desktop.
Helper functions for using devicectl to kill processes on connected iOS devices
# Add to your zsh profile
function devicepid() {
if [ -z "$1" ]; then
echo "Usage: devicepid <device-name> <search>"
echo "Example: devicepid 'iPhone 15 Pro Max' SpringBoard"
return 1
fi
if [ -z "$2" ]; then
echo "Usage: devicepid <device-name> <search>"
echo "Example: devicepid 'iPhone 15 Pro Max' SpringBoard"
return 1
fi
xcrun devicectl device info processes --device "$1" | grep "$2" | awk '{ print $1; }'
}
func devicekill() {
if [ -z "$1" ]; then
echo "Usage: devicekill <device-name> <process-name>"
echo "Example: devicekill 'iPhone 15 Pro Max' SpringBoard"
return 1
fi
if [ -z "$2" ]; then
echo "Usage: devicekill <device-name> <process-name>"
echo "Example: devicekill 'iPhone 15 Pro Max' SpringBoard"
return 1
fi
TARGETPID=$(devicepid "$1" "$2")
if [ $? -ne 0 ]; then
echo "Couldn't find PID for $2"
return 1
fi
echo "Found PID for $2: $TARGETPID"
xcrun devicectl device process signal --pid $TARGETPID --signal SIGHUP --device "$1"
}
func respring() {
if [ -z "$1" ]; then
echo "Usage: respring <device-name>"
return 1
fi
devicekill "$1" "SpringBoard"
}
func devicereboot() {
if [ -z "$1" ]; then
echo "Usage: devicereboot <device-name>"
return 1
fi
xcrun devicectl device reboot --device "$1"
}
@jeremyhu
Copy link

jeremyhu commented Oct 21, 2023

The stdout from devicectl isn't stable.

devicectl supports json output for a stable API. I suggest switching to that to ensure future updates don't break your scripts.

@insidegui
Copy link
Author

The stdout from devicectl isn't stable.

devicectl supports json output for a stable API. I suggest switching to that to ensure future updates don't break your scripts.

I'm aware. I actually have a more advanced tool I wrote in Swift that uses the JSON output, but for now these little helpers are doing the job just fine :)

@ltDino
Copy link

ltDino commented Dec 11, 2023

thanks!!! it helps me a lot!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment