A Javascript for Automation (Yosemite JXA) approach:
2 Likes
I made some adjustments to Rob Trew's script. Or rather I commented out the last section which I didn't understand.
And the change of desktop background wasn't needed for me so its also commented out.
I'm aware of the dilemma with a time trigger – this is for me to get used to Dark Mode. I'll probably remove that later on.
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;
//SET NIGHT BACKGROUND
//appSE.currentDesktop.picture = dctSettings.background.night;
strMode = "night";
} else {
appSE.appearancePreferences.darkMode = dctSettings.darkMode.day;
//SET DAY BACKGROUND
//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;
*/
}
Thanks for sharing!