如何用Applescript反转颜色?

时间:2014-11-04 03:40:56

标签: applescript

我正在研究如何使用Applescript反转颜色。在大多数情况下,我刚刚找到了类似的东西:

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

但是在优胜美地(我认为之前的版本),这将无法奏效。您必须进入系统首选项并在那里单击。那么,有没有办法制作一个可以反转颜色的AppleScript?(最好不要“点击”任何东西,因为这需要脚本的可访问权限)

3 个答案:

答案 0 :(得分:0)

您可以使用以下命令在Applescript中使用“do shell script”命令来实现此目的: 做shell脚本“sudo defaults write /Library/Preferences/.GlobalPreferences AppleInterfaceTheme Dark” 这应该在OS X Yosemite中打开“暗模式”。干杯!

答案 1 :(得分:0)

在Yosemite JXA Javascript中(如果您愿意,应该很容易适应AS) 一起切换黑暗主题和桌面颜色:

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;
}

答案 2 :(得分:0)

tell application "System Events"

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

end tell

它是 28 而不是 8 ,键码28是键盘主体上的“ 8”键。