Is it possible to dim the screen from Terminal, in a Mac with OS X Lion? Is there any command to do control brightness and volume?
3 Answers
You can do it via an Applescript and run it as such:
Dimmer:
tell application "System Events"
key code 144
end tell
Brighter:
tell application "System Events"
key code 145
end tell
You can save these as .script files and then run them from the CLI like this:
osascript ~/Path/to/File
You may refer to this.
You can also do it this way, but that requires more setup.
-
-
-
2The key codes should be 144 and 145, respectively. See osxdaily.com/2019/08/14/change-screen-brightness-mac-terminal Commented Oct 10, 2019 at 10:33
You can install this command line tool from github.com/nriley/brightness. The install is pretty easy if you have homebrew:
brew install brightness
And usage is straightforward:
- Set 100% brightness:
brightness 1
- Set 50% brightness:
brightness 0.5
Unfortunately it doesn't work for external monitors. See Does Apple support DDC/CI for 3rd party displays via Apple's Thunderbolt to DVI adapter for background on why.
-
For me, these instructions installed a command called
brightness
, notscreenbrightness
. Otherwise, this worked as described. Thanks!– octernCommented Oct 10, 2015 at 12:42 -
I think it have to do with a github merge of projects. When that happened they updated the command to
brightness
(which someone in Community happily already fixed in the answer).– studgeekCommented Jul 2, 2017 at 23:07 -
Note that the brightness Homebrew package is currently broken under macOS 10.13. See github.com/nriley/brightness/issues/21. Commented Sep 12, 2018 at 15:38
-
Does work for my external LG Ultrafine™ 5K, but I think that's an exception as it implements extra APIs– ijosephCommented May 30, 2022 at 3:46
I've created a node module for this that supports setting the brightness using the CLI. See https://github.com/kevva/brightness-cli.
npm install --global brightness-cli
And then simply just run brightness
from your command line.
-
Doesn't work for me:
$ brightness 100 /usr/local/lib/node_modules/brightness-cli/cli.js:3 const brightness = require('brightness'); ^^^^^ SyntaxError: Use of const in strict mode. at Module._compile (module.js:439:25) at Object.Module._extensions..js (module.js:474:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:312:12) at Function.Module.runMain (module.js:497:10) at startup (node.js:119:16) at node.js:902:3
– KibberCommented Jun 23, 2016 at 21:29 -