Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I detect the number of keyboards in OSX through command line using bash?

I am trying to write a bash script which can detect they number of keyboards currently connected to my MacBook Pro. The keyboards can be the

  • default one
  • any USB keyboards or
  • Bluetooth keyboard

Please give me any suggestions or areas I should be looking for. I am currently using a 2015 MacBook Pro running OSX 10.12.5. I am using the default terminal running bash 4.

like image 701
Sandilya Avatar asked Sep 01 '25 10:09

Sandilya


1 Answers

The ioreg command can be used to get a tree of all connected USB devices:

ioreg -p IOUSB

You can use sed to extract just the device names and grep to filter out the root nodes from the tree.

ioreg -p IOUSB -w0 | sed 's/[^o]*o //; s/@.*$//' | grep -v '^Root.*'
like image 120
Sandilya Avatar answered Sep 04 '25 04:09

Sandilya