List connected ios devices

Hi
I’m looking for a way to list all connected(thorough USB cable) IOS devices to macbook which appium runs on it(Getting the udid and name information about the devices).
Is something like that possible with appium client libraries or should I find a 3’rd party library to achieve that

Thanks

Use command xcrun instruments -s devices

Then you can parse output.
Pay attention that id of real devices is displayed without ‘-’

1 Like

Also you can use regular expression to detect only device lines in output.
Here you should use groups in Matcher too.

((.{0,})((.{0,}))\s{0,}\s[(.{0,})])|(((.{0,})((.{0,})))(\s-\s(.)))|((\w+ \w+ -)(\s-\s*(.)))|((\w\s-)(.*))

Thanks for the info
But I have another problem here when I run the instruments -s devices command it shows both simulators and real devices .
So how can I seperate real devices(Especially iphones) from simulators or macbooks

The way I do this is with ‘idevice_id -l’, which is installed with ideviceinstaller. ‘idevice_id -l’ will return the uuid’s of real devices only. If you store these in an array and parse the output from instruments into a hash you can do a quick comparison and create a hash of real devices only.

1 Like

I tried idevice_id also but this time I cannot get the name and info of the device
Is there any other solution to that

No it just gives you the UUID’s. So put them in an array and filter the hash that you’ve created from the instruments command above.

  1. Why you do not want use regular expression to skip rows which are not related to devices info?
  2. And then you just can skip lines which contain ‘-’

And you will have only real devices.

You can use method below to parse every line of output:

 private void parseToDevice(String line) {
        Pattern pattern = Pattern.compile("((.{0,})\\((.{0,})\\)\\s{0,}\\s\\[(.{0,})])|(((.{0,})\\((.{0,})\\))(\\s-*\\s*(.*)))|((\\w+ \\w+ -)(\\s-*\\s*(.*)))|((\\w*\\s\\-)(.*))");
        Matcher matcher = pattern.matcher(line);

        String UUID = "";
        if(matcher.find()) {
            UUID = matcher.group(4);
       
                if(!line.toLowerCase().contains("simulator") && !UUID.contains("-")) {
                PARSE REAL DEVICE INFO HERE AS YOU WISH
                }
        }
 }
1 Like

Ok I understand what you mean
I’ll try that

Thanks