如何使用AppleScript在Mac中设置低功率模式?

发布于 2025-01-19 07:30:46 字数 528 浏览 3 评论 0原文

新版本的 macOS 引入了电池和电源适配器的低功耗模式。我正在构建一个应用程序,作为我想使用 applescript/shell 脚本设置或取消设置低功耗模式的一部分。

这是我到目前为止所写的内容,它非常有效,我可以获取低功耗模式的当前状态,无论它是打开还是关闭。

tell application "System Preferences"
    do shell script "pmset -g | grep lowpowermode"
end tell

在上述步骤之后,我尝试“设置 lowpowermode 0”,但脚本抛出如下错误

tell application "System Preferences"
    do shell script "set lowpowermode 0"
        --> error number -10004

如何使用 applescript/shellscript 将低功耗模式设置为 0 或 1?

The new version of macOS introduced low power mode for battery and power adaptor. I am building an app, as a part of I would like to set or unset low power mode using applescript/shell script.

This is what I've written so far which works great where I can get the current status of low power mode whether if it is on or off.

tell application "System Preferences"
    do shell script "pmset -g | grep lowpowermode"
end tell

After the above step I tried to "set lowpowermode 0" but the script is throwing an error like below

tell application "System Preferences"
    do shell script "set lowpowermode 0"
        --> error number -10004

How do I set low power mode to 0 or 1 using applescript/shellscript?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

萤火眠眠 2025-01-26 07:30:46

在终端中尝试此操作:

sudo pmset -a lowpowermode 1

然后转到 Apple 菜单 -> 系统偏好设置 -> 电池,看看它看起来是否良好。


如果可行的话,我想你会在 Applescript 中这样做:

do shell script "pmset -a lowpowermode 1" with administrator privileges

Try this in the Terminal:

sudo pmset -a lowpowermode 1

Then go to Apple menu -> System Preferences -> Battery and see if it looks good.


If that works, I think you'd do it in Applescript something like this:

do shell script "pmset -a lowpowermode 1" with administrator privileges
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文