How can I find the device uuid's of all connected devices through a command line script?

穿精又带淫゛_ 提交于 2019-11-27 05:27:42

问题


I am running automated tests on iOS devices. I want to not have to always have all devices connected. So I want to find all device id's and then only start the process of building, deploying, and running tests if that device is connected.

So my question is, how can I find the device uuid's of all connected devices through a shell script?

Thanks!


回答1:


If you have Xcode installed, you can use Instruments to get all known devices also. With

instruments -s devices



回答2:


The answer from @KKendall set me on the right path. Here's a version with a single sed expression:

system_profiler SPUSBDataType | sed -n -E -e '/(iPhone|iPad)/,/Serial/s/ *Serial Number: *(.+)/\1/p'



回答3:


I found a similar question about using multiple devices here is my form of the answer that helped me:

 #!/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



回答4:


install ideviceinstaller on Mac OS X via brew command: brew install ideviceinstaller

then idevice_id -l will work from terminal




回答5:


Also ios-deploy can be used:

ios-deploy -c | grep -oE 'Found ([0-9A-Za-z\-]+)' | sed 's/Found //g'


来源:https://stackoverflow.com/questions/17237354/how-can-i-find-the-device-uuids-of-all-connected-devices-through-a-command-line

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!