如何检查Macbook Lid是否通过终端关闭? [英] How to Check if Macbook Lid is closed via Terminal?

查看:240
本文介绍了如何检查Macbook Lid是否通过终端关闭?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行OS X 10.8(Mountain Lion)。我想知道是否有终端命令来检查macbook pro的盖子是否当前关闭。如果我使用grep,我会准确查找哪些内容以及在哪里?



我之所以问这个问题,是因为我的计划任务是每30分钟运行一次。但是,当计算机正在休眠/休眠时,crontab不运行。我的解决方案是使用pmset每30分钟安排一次唤醒。但是,我需要一种方法在盖子当前关闭的情况下让电脑重新进入睡眠状态。我不希望我的电脑在盖子关闭的情况下长时间保持清醒状态,即在睡觉时整夜醒来,因为这会损坏屏幕。

方案

  ioreg -r -k AppleClamshellState -d 4 | grep AppleClamshellState |头部-1 

测试并运行于10.7。*,找到 here

更新2018-03-24 :



仍然适用于macOS 10.13 High Sierra。

I'm running OS X 10.8 (Mountain Lion). I was wondering if there was a terminal command to check if the macbook pro's lid is currently closed. If I used grep, what would I be looking for exactly, and where?

The reason I ask is because I have cron jobs scheduled to run every 30 minutes. However, crontab doesn't run when the computer is sleeping/hibernating. My solution was to use pmset to schedule wakes every 30 minutes. However, I need a way to put my computer back to sleep on the condition that the lid is currently closed. I don't want my computer to be awake for too long with the lid closed i.e. awake all night when I'm sleeping because that could damage the screen.

解决方案

ioreg -r -k AppleClamshellState -d 4 | grep AppleClamshellState  | head -1

Tested and works on 10.7.*, found here.

Update 2018-03-24:

Still works on macOS 10.13 High Sierra.

这篇关于如何检查Macbook Lid是否通过终端关闭?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆