Skip to content

Instantly share code, notes, and snippets.

@crespoxiao
Created December 5, 2017 01:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save crespoxiao/79043445cbfff77bf6cb07ef822bb8cf to your computer and use it in GitHub Desktop.
Save crespoxiao/79043445cbfff77bf6cb07ef822bb8cf to your computer and use it in GitHub Desktop.
iOS 命令行获取设备 UDID
1. 获取真机 udid
1)
system_profiler SPUSBDataType | sed -n -e '/iPad/,/Serial/p' -e '/iPhone/,/Serial/p' | grep "Serial Number:" | awk -F ": " '{print $2}'
2)
system_profiler SPUSBDataType | sed -n -E -e '/(iPhone|iPad)/,/Serial/s/ *Serial Number: *(.+)/\1/p'
3)
#!/bin/bash
function getUDID {
udid=($(system_profiler SPUSBDataType | grep -A 11 -w "iPad\|iPhone\|iPad" | grep "Serial Number" | awk '{ print $3 }'))
if [ -z $udid ]; then
echo "No device detected. Please ensure an iOS device is plugged in."
exit 1
else
for i in "${udid[@]}"; do
echo -n $i | pbcopy
echo "UDID: $i"
done
fi
}
getUDID
4)
#!/bin/sh
i=0
for line in $(system_profiler SPUSBDataType | sed -n -e '/iPad/,/Serial/p' -e '/iPhone/,/Serial/p' | grep "Serial Number:" | awk -F ": " '{print $2}'); do
UDID=${line}
echo $UDID
udid_array[i]=${line}
i=$(($i+1))
done
cnt=${#udid_array[@]}
for ((i=0;i<cnt;i++)); do
echo ${udid_array[i]}
done
5)
brew install ideviceinstaller
idevice_id -l
2.获取真机和模拟器的 udid
instruments -s devices
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment