I am looking for a script which will allow me to disable one specific USB port on my Mac mini. It would only serve a purpose if it works in real-time and didn't require a reboot. I've found scripts for various Linux distros that seemed to do something similar - however most required a reboot.

I've got ambient lighting behind my monitor which is powered by USB and it doesn't turn off when the system sleeps. So my office is constantly lit up, it would be nice if I could write a script that would disable that specific USB port.

How to disable individual USB ports by script?


Have you seen this thread and the code here? Maybe shell could be used to "manually" rename the device ID or port to something odd that won't work, upon a specified event, then renames it to what it's supposed to be later.

  • 1
    Hey I have looked at the recommended thread but the code specified is no longer available on the apple site. Could you please paste it, into your answer if you still have a copy?
    – Deesbek
    Oct 15 '13 at 0:22
  • I found the Google cache of the code and edited my comment above. I hope it helps— I don't know if this works or not, it was only an idea.
    – Elliott
    Oct 15 '13 at 3:51
  • Thanks, I am just interested as I am trawling through random questions and after reading the answer below was keen to try your solution myself.
    – Deesbek
    Oct 15 '13 at 4:10

Another way of attacking the problem could be to add a USB hub to the system and connect the ambient lighting to that.

Some USB hubs supports that you enable/disable individual ports from software - it is called "ganged power switching". That way you can control the lighting from a script. You will need to select a supported USB hub though.

I used this method for controlling power under Linux - but the same method could also be used on Mac OS X. The USB hub was very cheap.

You can find source code for controlling the external hub power here:


I don't know if it builds with libusb on Mac OS X, but it might.

  • Isn't "Per port power switching" when you can control individual port power, and "Ganged power switching" when you can only turn on/off all at once.
    – Joakim
    Nov 25 '14 at 14:14

Unfortunately, what you are asking is not possible with any OS X API or AppleScript hook. This is something controlled by the hardware layer of the OS and involves far more work than it's worth. While similar scripts exist for Linux, you must keep in mind that even though OS X and Linux are distant cousins, OS X wasn't built for such fine-grained control over its components like Linux was. Sadly, the only options you have in this case is to unplug the device or completely disable the USB interface. That last one, of course, isn't feasible for you, so unfortunately, there's no solution to this problem. Sorry. :(

Good luck and happy sleeping!

  • 3
    Can you cite a reason or documentation for "OS X wasn't built for such fine-grained control over its components like Linux was" Surely both Linux and OSX are Unix like OSs and have equal control over interfaces
    – mmmmmm
    Nov 16 '12 at 18:28
  • I think the USB power is controlled separately from the software. I temporarily removed all the IOUSB*.kext, and while the built-in trackpad and keyboard were dead, my kindle would still charge. (The iPhone wouldn't; but, that may be some Apple voodoo). By the way, don't remove all the IOUSB*.kext files unless you have a good recovery strategy (this particular macbook has multiple boot partitions, so, it will be easy to fix).
    – Kent
    Oct 15 '13 at 7:43

You must log in to answer this question.

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