0

I have created a script in Node.js that listens to USB devices being connected. When a certain USB device is connected, it launches a macOS app. Everything works as expected while having the lid opened.

I now want to incorporate that the script should check whether the lid is closed or not before launching the app. I can use this command (ioreg -r -k AppleClamshellState -d 4 | grep AppleClamshellState | head -1) for that. It should only launch the app if the lid is closed.

Without explaining the details around this, I can just say that the logic is working. I get a boolean whenever the USB device is connected that indicates whether the lid is open or closed, that I can use for executing the command that launches the app if the lid is closed.

But I then tested starting the script, closing the lid and connecting the device. And nothing happens. I can determine this with the USB device since there is a display on it that goes to a particular view when the app is open. When I open the lid again, that's when the app launches and things work as intended. So it seems like the process of launching the app while having the lid closed is being put on a halt until I open the lid again.

I'm running macOS Monterey 12.6.3 on a MacBook Pro (15", mid-2015). I have the charger connected and I've made sure to have 'Prevent your Mac from automatically sleeping when the display is off' checked under 'System Preferences / Battery'. I'm not using an external monitor.

What I would like is for the app to launch properly even with the lid closed. Would be even better if this could be done without having the charger connected. Any ideas on how to achieve this?

2 Answers 2

0

When connecting a USB device to a closed MacBook Pro, macOS briefly wakes to evaluate the USB device and then promptly returns to a low power state.

By default macOS will not run third party software when a MacBook Pro's lid is closed and no monitor is attached. When the lid is closed, the MacBook Pro sleeps.

As a work around, you may be able to disable sleep on your MacBook Pro.

0

To work in closed clamshell mode, macOS requires you to connect three things:

an external display, a mouse, and a keyboard

Once that is done, macOS will allow apps to run instead of limited system only validations of a device to charge only or charge and send data over the USB or Thunderbolt bus.

You must log in to answer this question.

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