75

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!

SirRupertIII
  • 12,324
  • 20
  • 72
  • 121

6 Answers6

133

Edit:

instruments command is now deprecated, you should run instead

xcrun xctrace list devices

Previous answer:

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

instruments -s devices
Dominik Bucher
  • 2,120
  • 2
  • 16
  • 25
Quanlong
  • 24,028
  • 16
  • 69
  • 79
  • 4
    +1 for an answer that allows parsing. This prints out the device list in a single-line format. alternately, one can also use ios-deploy -c (which admittedly is not an Apple-only solution) – Vish Jul 14 '15 at 05:15
  • 1
    Does this command still works? According to the Xcode docs `instruments -s`just lists the available templates which is the result I get when I execute the command mentioned above, but that is not a device list. – Robert Nov 18 '15 at 15:11
  • 1
    The output list should include your device list. – Quanlong Nov 18 '15 at 17:24
  • 1
    @Quanlong can we save this devices list to a variable. I need to save this in a variable and search a device from this list. I am using shell script. – Qadir Hussain Oct 31 '16 at 12:48
  • 1
    how to get UDID of simulator as well along with device ? – vikramvi Aug 17 '17 at 14:48
  • This one gives list of attached simulators as well. – Darpan May 25 '18 at 14:16
  • Using `xcrun xctrace list devices` if you have Xcode 12.1 installed. – Yongqiang Zhou Nov 20 '20 at 07:07
  • The new `xcrun xctrace list devices` isn't quite good to work with because you cannot easily `grep` simulator vs real devices because it shows 2 tables instead of the device type in brackets. I'd recommend stick to instruments for better flexibility until it's completely deleted... – Dominik Bucher Jan 27 '21 at 11:00
  • `xcrun xctrace list devices` doesn't work for me here in 6/2023. It returns the wrong devices. Now I use `ios-deploy -c -t 1 -W -C -j` – kraftydevil Jun 09 '23 at 08:37
26

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'
Jay Lieske
  • 4,788
  • 3
  • 30
  • 41
21

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

then idevice_id -l will work from terminal

Xiao
  • 12,235
  • 2
  • 29
  • 36
14

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
Community
  • 1
  • 1
SirRupertIII
  • 12,324
  • 20
  • 72
  • 121
  • 1
    It looks that answer not actual right now because new apple devices have ids with "-" like 00008027-0001713202E8002E but system_profiler shows id without "-" : Serial Number: 000080270001713202E8002E – Degard Jan 31 '19 at 09:25
8

Also ios-deploy can be used:

ios-deploy -c | grep -oE 'Found ([0-9A-Za-z\-]+)' | sed 's/Found //g'
Degard
  • 192
  • 1
  • 7
  • 1
    This works, but will include newlines in some cases. Adding " | tr -d \'\r\n\'" fixes that. – BevTheDev Nov 27 '19 at 00:20
  • Works best for me in 6/2023 since `xcrun xctrace list devices` is broken, returning the wrong devices. Now I use `ios-deploy -c -t 1 -W -C -j` – kraftydevil Jun 09 '23 at 08:36
4

If you have XCode go to Window > Devices & Simulators. On that page, any connected device will display along with other IDs and stats on your device. This will also connect to devices over WIFI.

Rivers
  • 2,102
  • 1
  • 16
  • 27