GithubHelp home page GithubHelp logo

noclamshell's Introduction

No clamshell mode

What is a clamshell mode? As per this doc:

You can use an external display or projector with a Mac notebook while its built-in display is closed. This is known as "closed-clamshell" or "closed-display" mode.

Basically, when you're connected with power adapter and there's an external monitor connected, when you close the lid, nothing happens.

But this mode doesn't fit all, and there's still no good solution, and there is no option to turn it off in settings. Some tricks exist, none of them gets you a sleeping machine when just closing the lid:

  • unplug power adapter, close lid, plug power back;
  • close lid, unplug power adapter, plug power back;
  • before closing the lid, press power button (actually long-press it and then click on "Sleep");
  • put external display off using a hot corner, close lid

Some discussion threads from back then and pretty recent as well.

Less fuss

Imagine a magic script that monitors your lid state, and when it is closed, puts your machine to sleep. Here it is!

How does this work

It periodically checks if lid is closed and puts machine to sleep. Nothing fancy, it uses command line tools that come with OSX, specifically ioreg, which displays I/O registry and pmset to manipulate power management settings.

Installation

brew install pirj/noclamshell/noclamshell
brew services start noclamshell

Uninstall

In case utility didn't work as you expected, you can turn it off:

brew services stop noclamshell
brew uninstall pirj/noclamshell/noclamshell

Please drop me a note on what went wrong!

Self-ad

I also maintain an utility that reduces the brightness of internal display to zero when lid is open. Appreciate if you check it out!

Blah

Author: Phil Pirozhkov

Contributors:

License: MIT

noclamshell's People

Contributors

cfstras avatar pirj avatar ris58h avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

noclamshell's Issues

Not working with macOS Big Sur

Unfortunately I get the following responses when trying to install the package via Terminal / Homebrew:

Error: Your CLT does not support macOS 11.0.
Error: Formula noclamshell is not installed.

When I run the file from the zip-archive, it tells me:

[Process completed]

Unfortunately it doesn't work afterwards.

homebrew services file

Not really an issue, but a question. I see this script uses "brew services", which I assume is a lot like linux systemd. Where can I find a copy of the services file? I'm curious how the noclamshell script is periodically called.

I need this for my work laptop, but I can't install brew due to corporate policy. I guess I could just setup a crontab to run noclamshell every X minutes. Do any of those commands require root access to run?

Didn't seem to work for me on Big Sur 11.1

Hi, I've just checked it out, the service is running, but closing the lid just behaves as it always did, and the macbook stays on.
Is there any extra step I'm missing?

Doesn't seem to work

Hey there,

before I start I'd like to say that I saw the other threads where ppl said they can’t get it to work but didn’t respond anymore.

What's happening?
My laptop, a 2016 macbook pro 15" with Touch Bar, still enters a clamshell like mode when closing it when connected to a mointor with power. Before installing it would constantly run, get warm and output something to the display when plugged into my monitor even when not used, no matter if I plug it in when the lid is closed or close the lid after plugging it in.
Now with noclamshell, also no matter what order, if I plug it in before closing the lid or the other way, it still acts the same way with one exception: There is not output to the monitor at all. Even when the lid is open. When the lid is closed, the laptop still acts like before, it heats up and does something. Also I noticed that since I installed noclamshell, I get problems with teamviewer just showing a dark blank screen.

What did I try to fix it?
I reinstalled it with brew as explained and I am not getting an error when running /usr/local/bin/noclamshell. I also tried a few of the other steps that were mentioned in other threads without success.

I hope I gave sufficient info and that this can be solved easily since this app would be an ideal solution.

Not working on Macbook Pro / High Sierra / Apple Thunderbolt Display

Hey! Not sure why, but it's not working for me (which is devastating, because this is the only coherent solution I've found to our shared problem).

MacBook Pro (Retina, 13-inch, Late 2013)
macOS High Sierra v 10.13.1

I'm using an 27-inch Apple Thunderbolt Display which is also the source of power to the laptop.

I've tried restarting my computer and confirmed that noclamshell is running on start. But closing my laptop lid just causes the external monitor to flicker before turning back on and staying on =/.

$ brew services start noclamshell
Service `noclamshell` already started, use `brew services restart noclamshell` to restart.
$ brew services restart noclamshell
Stopping `noclamshell`... (might take a while)
==> Successfully stopped `noclamshell` (label: homebrew.mxcl.noclamshell)
==> Successfully started `noclamshell` (label: homebrew.mxcl.noclamshell)
$ 

Machine fails to wake up

I would love to have my MacBook sleep when I close the lid even though an external screen is connected. At the moment, I have to unplug the monitor (which also powers the laptop) to ensure it will go into standby mode.

I have a 2016 MacBook Pro, and used the script with an external USB-C screen attached, which also powers the machine.
Closing the lid caused the MacBook to crash each time (full system crash, and an automatic reboot afterwards).

I've temporarily removed the script using:
launchctl unload ~/Library/LaunchAgents/noclamshell.plist

It would be good to include this in your documentation as well.

Have to `brew services restart noclamshell` every few days.

Every so often, usually about 3 -5 days I close my laptop and it goes into clamshell mode. I to run brew services restart noclamshell and it fixes it. The service appears to be running prior to this because the output of that command is:

Stopping `noclamshell`... (might take a while)
==> Successfully stopped `noclamshell` (label: homebrew.mxcl.noclamshell)
==> Successfully started `noclamshell` (label: homebrew.mxcl.noclamshell)

Laptop is a 2020 Intel Macbook Pro 16in connected to an Asus display. Power + display in the same USB-C cable.

I have a cron job that restarts noclamshell automatically every day at noon, but this issue still happens.

"Failure while executing" on Big Sur

brew services start noclamshell

returns

Error: Failure while executing; /bin/launchctl bootstrap gui/501 /Users/lucas/Library/LaunchAgents/homebrew.mxcl.noclamshell.plist exited with 5.

Permission denied

When I try running brew services start noclamshell I get permission denied error. When I use sudo, I get Warning: noclamshell must be run as non-root to start at user login! Not sure if this is a bug, user error, or a permission error with my company laptop (though I've installed homebrew scripts before with no issue). Appreciate any help! Thank you!
Screen Shot 2021-11-29 at 11 47 12 AM

Not working on M1 MacBook Air

It seems that neither "AppleDisplay" nor "IODisplayWrangler" is present in the M1 pmset.

Here is a difference of pmset -g powerstate between lid closed and open:

--- powerstate.lidclosed        2021-03-01 21:01:37.000000000 +0100
+++ powerstate.regular  2021-03-01 21:01:45.000000000 +0100
@@ -332,12 +332,15 @@
 AppleDCPDPTXRemotePortPr    0          0  None
 AppleDCPDPTXRemotePortPr    1          1  USEABLE
 DCPDPDeviceProxy            0          0  None
+DCPDPDeviceProxy            0          0  None
 AppleCLCD2                  1          1  USEABLE
 AppleCLCD2                  1          1  USEABLE
 AppleSMC                    1          1  USEABLE
 AppleSmartBatteryManager    1          1  ON
 AppleDCPExpert              1          1  ON
 AppleDCPExpert              1          1  ON
+DCPDPDeviceProxy            0          0  None
+DCPDPDeviceProxy            0          0  None
 AppleCLCD2                  1          1  USEABLE
 AppleCLCD2                  1          1  USEABLE
 AppleHPMARM                 1          1  USEABLE

I've fixed the issue by adding these lines directly below if [ "$LID_CLOSED" ]; then in my /opt/homebrew/bin/:

CLAMSHELL=$(pmset -g powerstate | grep DCPDPDeviceProxy | wc -l)
if (( CLAMSHELL < 4 )); then
  pmset sleepnow
fi

Which seems like a really ugly hack, but it works for me. Don't know how to detect whether these should be present cleanly though... ($(uname -m) == "arm64")?

Mac m1 pro not going to sleep

Hey @pirj , first of all, thanks for this tool, because this seems like the only tool that actually is working for a lot of people.
Unfortunately not for me.

Problem:
Installed the service and started it, also I keep an external display, mouse, keyboard connected through usb c.
But whenever I disconnect charger and close the lid, I expect that it should go to sleep with your service, but I doubt it sleeps because the next day battery is still very low like it used to be without this service.
Check the battery usage over Weekend(S and S in pic), its almost 0 after that
image

Also if I disconnect all the external devices, and disconnect charger and close the lid, it would go to sleep no problem. But in that case it goes to sleep without this service as well.

This is what brew services list shows:
image

I hope you can help me.
Thanks.

This seems eat lots of CPU resource

Oh boy, I am wondering why my laptop keeps freeze everyday with high CPU usage for a long time until I remember this. Tried to turn this off, and I can't even hear the fan anymore....

Is there any optimization we can do to slow this down? like run the loop every second?

(duplicated #5 because I created the issue with wrong account)

cannot run at all

big sur 11.6, macbook pro m1. After running brew services start noclamshell I get:

Bootstrap failed: 5: Input/output error
Error: Failure while executing; `/bin/launchctl bootstrap gui/501 /Users/alpha/Library/LaunchAgents/homebrew.mxcl.noclamshell.plist` exited with 5.

`Bootstrap failed: 5: Input/output error` on start

Hi there, just wanted to test this script. I'm on a MacBook 16" with M1 Pro.

After installing and starting I just get the mentioned Error.
The complete output is

~ brew services start noclamshell          
Bootstrap failed: 5: Input/output error
Try re-running the command as root for richer errors.
Error: Failure while executing; `/bin/launchctl bootstrap gui/501 /Users/mkr/Library/LaunchAgents/homebrew.mxcl.noclamshell.plist` exited with 5.

If I look at brew services list it's visible there, but "scheduled".

Here a screenshot of my full terminal until the error.
Bildschirmfoto 2024-01-26 um 11 02 20

Eject external drives before sleep?

Hi, not sure if you have the bandwith for this specific use case, but figured I'd ask. I keep my M2 Air plugged in to a hub that charges, connects to ethernet, monitor, and also my Time Machine backup external drive. When I close my lid and the mac goes to sleep, once I turn it back on, I have notifs that the drive was ejected incorrectly.

I have the app Ejectify (https://ejectify.app) which is supposed to automatically eject the drives when the mac goes to sleep, but it does not work consistently, and I got the thought that maybe it has some sort of conflict with how noclamshell puts the computer to sleep. I don't know how their app works exactly, and I obviously don't expect you to know how might interact - but is there anything in particular you can tell me about how noclamshell puts the computer to sleep that differs significantly from the normal process of putting it to sleep? That might give me a lead to go to Ejectify's devs about.

Doesn't sleep the same way it does when manually triggered

It seems the sleep initiated by noclamshell isn't the same as the one when you manually enter sleep mode on M1.
Here's how noclamshell sleep differs from normal sleep:

  • Plugged in USB devices continue being powered (with manual seep the USB devices go offline)
  • When the lid is opened, it seems to come back quicker (as if just the display was off) compared to when I manually put it in sleep
  • It remains connected to the network (while with normal sleep it kills all connections after about 5 seconds)
  • I can feel the laptop being slightly warm even when it has been closed (with external monitor sleeping) for several hours - indicating it isn't really sleeping

Keep in mind all other behavior is the same as normal (manually triggered) sleep.
Kudos!

Had to reinstall after upgrade from Big Sur to Monterey

No complaints really, just letting you know this happened. Error I got while trying to manually start after upgrade:

Error: Failure while executing; `/bin/launchctl bootstrap gui/501 /Users/xxx/Library/LaunchAgents/homebrew.mxcl.noclamshell.plist` exited with 5.

Uninstalled and reinstalled as per README and all good again.

mac won't awake

I connected 2 external monitors and first time it worked fine, but the second time, mac wouldn't awake when lid is back to open. Had to restart the system.

Error: Cannot install on m1 Mac

Error: Cannot install in Homebrew on ARM processor in Intel default prefix (/usr/local)!
Please create a new installation in /opt/homebrew using one of the
"Alternative Installs" from:
https://docs.brew.sh/Installation
You can migrate your previously installed formula list with:
brew bundle dump

Homebrew deprecation warning

When calling brew upgrade or brew doctor, I get the following warning:

Calling plist_options is deprecated! Use service.require_root instead.
Please report this issue to the pirj/noclamshell tap (not Homebrew/brew or Homebrew/homebrew-core), or even better, submit a PR to fix it:
/opt/homebrew/Library/Taps/pirj/homebrew-noclamshell/Formula/noclamshell.rb:11

For reference, line 11 is this:

plist_options manual: "noclamshell"

This seems eat lots of CPU resource

Oh boy, I am wondering why my laptop keeps freeze everyday with high CPU usage for a long time until I remember this. Tried to turn this off, and I can't even hear the fan anymore....

Is there any optimization we can do to slow this down? like run the loop every second?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.