2011-06-28 22 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; 

をだから今、私は設定は、画面反転を担当しているか知っています。しかし、私が明白にしようとすると、何も起こりません。おそらく、これらの値を使用するプログラムであれば、リロードするように指示する必要があります(例: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 

これは、Control-Optionキーを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 
関連する問題