如何使用Applescript反转颜色?

如何使用Applescript反转颜色?,applescript,Applescript,我在研究如何用Applescript反转颜色。在大多数情况下,我只是发现了如下内容: tell application "System Events" keystroke "8" using {command down, option down, control down} end tell 但在约塞米蒂(我认为这之前的版本),这是行不通的。您必须进入系统首选项并在其中单击。那么,有没有一种方法可以制作一个可以反转颜色的applescript?(最好不必“单击”任何东西,因为这需要脚

我在研究如何用Applescript反转颜色。在大多数情况下,我只是发现了如下内容:

tell application "System Events"
    keystroke "8" using {command down, option down, control down}
end tell 

但在约塞米蒂(我认为这之前的版本),这是行不通的。您必须进入系统首选项并在其中单击。那么,有没有一种方法可以制作一个可以反转颜色的applescript?(最好不必“单击”任何东西,因为这需要脚本的访问权限)

您可以通过使用applescript中的“do shell script”命令来实现这一点,使用以下方法: 执行shell脚本“sudo defaults write/Library/Preferences/.GlobalPreferences AppleInterfaceTheme Dark”
这应该在OSXYosemite中打开“暗模式”。干杯

约塞米蒂JXA Javascript中的(如果您愿意,应该可以很容易地适应) 同时切换深色主题和桌面颜色:

function run() {
    var dctSettings = {
            darkMode: {
                day: true,
                night: false
            },
            background: {
                day: "/Library/Desktop Pictures/Solid Colors/Solid Gray Pro Ultra Dark.png",
                night: "/Library/Desktop Pictures/Solid Colors/Solid Gray Light.png"
            }
        },
        strMode;


    app = Application("System Events");

    if (app.currentDesktop.picture() === dctSettings.background.day) {
        app.currentDesktop.picture = dctSettings.background.night;
        app.appearancePreferences.darkMode = dctSettings.darkMode.night;

        strMode = "Night";

    } else {

        app.currentDesktop.picture = dctSettings.background.day;
        app.appearancePreferences.darkMode = dctSettings.darkMode.day;

        strMode = "Day";
    }
    return strMode;
}

它是28而不是8,28键是键盘主要部分的“8”键。

我刚刚试过。它给了我这个错误:“sudo:没有tty存在,也没有指定askpass程序”
tell application "System Events"

key code 28 using {command down, option down, control down}

end tell