10

Assume I have a Galaxy phone connected via USB to my mac

Listing USB devices is easy, and I can see my phone connected:

ioreg -p IOUSB -l -w 0

Is it possible, given I have the ioreg output, to disconnect a specific device (without PHYSICALLY disconnecting it)?

2
  • To clarify, by "disconnect", do you mean you want to unmount it from the file system, or make it invisible to your computer? Also, if the former, would you like to be able to reconnect it without needing to unplug it and plug it back in? – Tuesday Feb 1 '17 at 19:27
  • @timothymh regardless what he is asking, I like to know how to remove a device from diskutil and add it back. Unmount command doesn't remove a device. Right click the device icon and select eject is different, it CAN remove a device from the diskutil, and the only way to add it back is to physically replug it. – aeroxy Aug 1 '17 at 5:55
4

It turns out that there is a way of doing this not only in macOS, but in all *NIX systems thanks to the mvp/uhubctl repository over on GitHub. The program is called uhubctl, and allows you to toggle and cycle power on individual ports for supported USB hubs.

As the description would imply, you'll need to know which USB port the device in question is connected to (or cycle the entire hub if you're confident it won't cause and issues with other peripherals), and I still recommend using diskutil eject diskX (or sudo umount /dev/sdX for Linux and umount diskX for BSD) before power cycling the port to ensure that the device unmounts cleanly.

uhubctl home page is here (you can get source code using git clone https://github.com/mvp/uhubctl).

You'll need to compile it from source one way or another, either with make or via brew. By far easiest way to install it in one swoop with brew:

brew tap mvp/uhubctl https://github.com/mvp/uhubctl  
brew install uhubctl

Tested and can confirm working with both Apple and 3rd party USB hubs on macOS 10.13-10.15, and on macOS 11 Big Sur too (including M1 Macs).

1
  • How to get it to work with notebook USB-C ports? It only shows me ports on connected USB hubs. Thank you. – nisc Jun 6 at 23:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .