Turn off USB power on OS X/Mac Mini

I have a need to turn USB power off (and on) using a script or a piece of software. Ideally it should be possible to turn each port off/on separately, but also turning power off/on from all ports at once is sufficient. The machine I am using is Mac Mini. Anyone has a solution for this?

By USB power I mean Vbus, the 5V/500mA connection. I understand that the data connection is also turned down and it is fine, but it is not enough for me that the data connection is down and Vbus remains powered. This need comes from the need to keep mobile phones constantly connected for automatic testing. Some device/battery combinations do not like to be constantly connected and batteries start swelling in less than a year.

I recognize that multiple variations of this question are around. So far no solution that I could use. I'll list here my findings so far:

  • it is possible to accomplish this by using external self powered USB HUB and controlling it's power. However, this is not an option for me (even quality hubs have caused other problems in my use).

  • it is possible to disable USB by removing .kext files. Among other sources it is explained in OS X Security configuration document. However this requires reboot and I am not sure if it really disables USB power or just data.

  • there are many claims that it just is not possible. However, OS X itself does it when it detects a device that consumes too much power, so there is at least hardware support. This error message is copied from /System/Library/Extension/IOUSBFamily.kext/Contents/Resources/English.lproj/Localizable.strings: "Unplug the device using too much power to re-enable USB devices." (of course I don't know if the disabling is done by turning off USB power, but I would assume it is natural action for the device that consumes too much of it).

  • it seems that on macbook the USB ports are normally powered even when the laptop is sleeping. While this is not solving my issue, it is kind of related.

The reason why I need this is that I have a test system where multiple devices are plugged in to a mac mini. The devices also charge over USB. It has turned out that if the device is connected all the time to a charger, it's battery is swollen in about a year, which makes the device unusable, insecure and potentially dangerous. Turning the power off when not needed, would significantly extend devices life.


I spent a lot of time researching this problem some years ago - my conclusion is that it is simply not possible with the information available to us. The control of the power happens at a much lower level than the macOS kernel itself, so it is not just a question of configuring macOS or poking at the right kernel data structure. You have to modify firmware which is not possible for ordinary users.

The only working solution I found is to use a hub. This worked very well for me. If you have a hub that supports ganged power switching, you can easily turn off/on the power for each gang (set of ports). Similarly if you have a hub that supports per-port power switching, you can turn off/on each port on the hub individually.

You can download software for macOS to control the hub from here:

https://github.com/mvp/uhubctl

Note that this utility only supports controlling hubs that allow per-port power switching. The web site has a list of supported USB hubs.

Once I went with the hub solution, the hardest part really was finding a USB hub that supports ganged or per-port power switching. The actual software part is very easy.