2011-06-28 43 views
5

如何编写脚本以在Mac上运行以反转屏幕颜色?如何以编程方式反转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才能生效)。但我不确定那些应用会是什么,或者无论如何这是否是正确的解决方案。

+0

你为什么要这么做? –

+0

提醒自己在编码时定期查看屏幕。建议? –

+0

我猜想WindowServer进程需要微调来注意设置更改,但我不知道如何。如果你真的杀了WindowServer,我认为它会杀死任何GUI应用程序。 – JWWalker

回答

4

苹果脚本的这个片段将做到这一点:

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

这里使用了控制 - 备选-CMD-8快捷键(键码28是8号)。你必须弄清楚如何从你需要的任何地方调用它...

+0

如果我在调用脚本时键入,这似乎会导致故障。有没有不涉及模拟击键的解决方案? –

+0

对不起,我不知道...我对Mac GUI编程知之甚少。推测这个键盘快捷方式正在调用一些其他的底层通话,但我不知道。 – spacemanaki

+1

为了达到此目的,您必须在系统偏好设置>通用访问>启用辅助设备访问权限中选中该框 – roberthuttinger

1

你可以尝试完善这个片段,它返回当前状态与GUI脚本。该值似乎是只读的,并尝试将其设置为1或0失败。

tell application "System Preferences" 
    launch 
    set current pane to pane "com.apple.preference.universalaccess" 
    tell application "System Events" 
     return value of checkbox "Invert colors" of window 1 of process "System Preferences" 
    end tell 
    quit 
end 
1
tell application "System Preferences" 
    activate 
    reveal anchor "Seeing_Display" of pane id "com.apple.preference.universalaccess" 
    tell application "System Events" to tell process "System Preferences" 
    click the checkbox "Invert colors" of window "Accessibility" 
    end tell 
end tell 
tell application "System Preferences" to quit 
相关问题