Skip to content

Instantly share code, notes, and snippets.

@phuctm97
Last active March 19, 2020 12:42
Show Gist options
  • Save phuctm97/6546dbd640469e0653f484940f26e7b1 to your computer and use it in GitHub Desktop.
Save phuctm97/6546dbd640469e0653f484940f26e7b1 to your computer and use it in GitHub Desktop.
Automation script to configure macOS preferences from command line
#!/bin/bash
osascript -il JavaScript prefs.js
// Options.
const prefs = {
appearance: {
appearance: "blue", // the overall look of buttons, menus and windows.
fontSmoothing: true, // is font smoothing on?
fontSmoothingStyle: "automatic", // the method used for smoothing fonts ("automatic", "light", "medium", "standard" or "strong").
highlightColor: "blue", // color used for hightlighting selected text and lists ("blue", "gold", "graphite", "green", "orange", "purple", "red" or "silver").
recentApplicationsLimit: 0, // the number of recent applications to track.
recentDocumentsLimit: 0, // the number of recent documents to track.
recentServersLimit: 0, // the number of recent servers to track.
scrollBarAction: "jump to next page", // the action performed by clicking the scroll bar.
smoothScrolling: true, // is smooth scrolling used?
darkMode: true // use dark menu bar and dock.
},
dock: {
animate: true, // is the animation of opening applications on or off?
autohide: true, // is autohiding the dock on or off?
dockSize: 0.25, // size/height of the items (between 0.0 (minimum) and 1.0 (maximum)).
magnification: false, // is magnification on or off?
magnificationSize: 0, // maximum magnification size when magnification is on (between 0.0 (minimum) and 1.0 (maximum)).
minimizeEffect: "genie", // minimization effect ("genie" or "scale").
screenEdge: "left", // location on screen ("bottom", "left" or "right").
}
};
// Configurations.
const App = Application.currentApplication();
App.includeStandardAdditions = true;
App.strictPropertyScope = true;
App.strictCommandScope = true;
App.strictParameterType = true;
const SystemEvents = Application("System Events");
// Apply.
function apply() {
for(let k in prefs.appearance) {
SystemEvents.appearancePreferences[k] = prefs.appearance[k];
}
for(let k in prefs.dock) {
SystemEvents.dockPreferences[k] = prefs.dock[k];
}
}
// Check.
function check() {
const currPrefs = {
appearance: {},
dock: {}
};
for(let k in prefs.appearance) {
currPrefs.appearance[k] = SystemEvents.appearancePreferences[k]();
}
for(let k in prefs.dock) {
currPrefs.dock[k] = SystemEvents.dockPreferences[k]();
}
return currPrefs;
}
function run() {
console.log(JSON.stringify(check(), null, 2));
}
#!/bin/bash
# Install XCode command line tools.
xcode-select --install
# Install Homebrew.
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment