如何编写在Mac上运行的可反转屏幕颜色的脚本?

How to programmatically invert screen colors in Linux类似,但是据我所知,xcalib可以在Windows和Linux上运行,但不能在Mac上运行。

编辑:我有部分解决方案。我发现了一种在反转屏幕颜色之前和之后转储所有设置的方法:

$ mkdir before && mkdir after && cd before
$ for d in $(defaults domains | sed 's/,//g'); do defaults read $d > $d; done
$ cd ../after
$ # System Preferences > Universal Access > Display > White on Black
$ for d in $(defaults domains | sed 's/,//g'); do defaults read $d > $d; done
$ diff -r before after
diff -r before/com.apple.CoreGraphics after/com.apple.CoreGraphics
3c3
<     DisplayUseInvertedPolarity = 0;
---
>     DisplayUseInvertedPolarity = 1;
diff -r before/com.apple.universalaccess after/com.apple.universalaccess
5c5
<     whiteOnBlack = 0;
---
>     whiteOnBlack = 1;

所以现在我知道哪些设置负责屏幕反转。但是当我尝试显而易见的时候
$ defaults write com.apple.universalaccess whiteOnBlack -int 1
$ defaults write com.apple.CoreGraphics DisplayUseInvertedPolarity -int 1

没发生什么事。大概任何使用这些值的程序都需要被告知要重新加载它们(因为来自dotfiles的示例需要杀死Finder才能生效)。但是我不确定这些应用程序是什么,还是不确定这是否是正确的解决方案。

最佳答案

Apple Script的以下代码片段可以做到这一点:

tell application "System Events"
    key code 28 using {control down, option down, command down}
end tell

这使用Control-Option-Cmd-8快捷键(键码28为数字8)。您必须弄清楚如何从任何需要的地方调用它...

关于macos - 如何在Mac上以编程方式反转屏幕颜色,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6511304/

10-13 08:52