Skip to content

Instantly share code, notes, and snippets.

@hungtcs
Last active September 5, 2022 10:11
Show Gist options
  • Save hungtcs/c7dbb934bafc65bf71c580f2f6a014a7 to your computer and use it in GitHub Desktop.
Save hungtcs/c7dbb934bafc65bf71c580f2f6a014a7 to your computer and use it in GitHub Desktop.
Mac OS 通过 CLI 对系统进行控制

深色模式

切换深色模式

tell application "System Events"
    tell appearance preferences
        set dark mode to not dark mode
    end tell
end tell

屏幕亮度

设置亮度:

# 提高亮度
osascript -e 'tell application "System Events"' -e 'key code 144' -e ' end tell'

# 降低亮度
osascript -e 'tell application "System Events"' -e 'key code 145' -e ' end tell'

获取亮度等级:

  1. brightness 命令不支持 M1 芯片的MacBook,其他机型未测试

音量

获得音量等级:

osascript -e 'get volume settings'

可能的输出:

# 静音
output volume:0, input volume:100, alert volume:100, output muted:true

# missing
output volume:missing value, input volume:100, alert volume:100, output muted:missing value

# 数值
output volume:28, input volume:100, alert volume:100, output muted:false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment