Created
February 24, 2015 13:06
-
-
Save RobTrew/dcaa2161bfcce5653992 to your computer and use it in GitHub Desktop.
OS X Yosemite Javascript for Applications (JXA): Toggling background, dark mode, and screen color inversion between day ⇄ night settings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function run() { | |
// Rob Trew 2015 | |
// Ver 0.01 | |
// UI day/night toggling through OS X 10.10 JXA Javascript for Automation | |
// SWITCH FROM DAY-TIME DARK MENU BAR AND DOCK WITH DARK BACKGROUND | |
// TO NIGHT-TIME *ALL DARK* | |
// (TOGGLE MODE AND BACKGROUND TO BRIGHT, THEN INVERT ALL) | |
// Edit to your preferred settings for day and night here: | |
var dctSettings = { | |
darkMode: { // System Preferences > General > Use dark menu bar and dock | |
day: true, | |
night: false | |
}, | |
invert: { // System Preferences > Accessibility > Display > Invert Colors | |
day: 0, | |
night: 1 | |
}, | |
background: { | |
day: "/Library/Desktop Pictures/Solid Colors/Solid Gray Pro Ultra Dark.png", | |
night: "/Library/Desktop Pictures/Solid Colors/Solid Gray Light.png" | |
} | |
}; | |
var appSE = Application("System Events"), | |
appPrefs = Application("System Preferences"), | |
chkInvert; | |
// Toggle the dark mode and dark background, and record the new mode as [night|day] | |
if (appSE.appearancePreferences.darkMode() === dctSettings.darkMode.day) { | |
appSE.appearancePreferences.darkMode = dctSettings.darkMode.night; | |
appSE.currentDesktop.picture = dctSettings.background.night; | |
strMode = "night"; | |
} else { | |
appSE.appearancePreferences.darkMode = dctSettings.darkMode.day; | |
appSE.currentDesktop.picture = dctSettings.background.day; | |
strMode = "day"; | |
} | |
// open the Display panel of Universal Access | |
appPrefs.activate(); | |
appPrefs.panes.byId( | |
"com.apple.preference.universalaccess" | |
).anchors.byName("Seeing_Display").reveal(); | |
// read the state of the color inversion checkbox | |
chkInvert = appSE.applicationProcesses.byName( | |
"System Preferences" | |
).windows.byName("Accessibility").checkboxes.byName("Invert colors"); | |
// and click it if it doesn't match the new [day|night] mode | |
if (chkInvert.value() !== dctSettings.invert[strMode]) { | |
appSE.click(chkInvert); | |
} | |
appPrefs.preferencesWindow.close(); | |
return strMode; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment