bootedSimulatorsNamed function
The UDIDs of the booted simulators called name, from the JSON of
simctl list devices booted -j.
Implementation
List<String> bootedSimulatorsNamed(String name, String json) {
final Object? decoded;
try {
decoded = jsonDecode(json);
} on FormatException {
return const [];
}
final Object? runtimes = decoded is Map ? decoded['devices'] : null;
if (runtimes is! Map) return const [];
return [
for (final Object? devices in runtimes.values)
if (devices is List)
for (final Object? device in devices)
if (device is Map &&
device['name'] == name &&
device['state'] == 'Booted' &&
device['udid'] is String)
device['udid'] as String,
];
}