Skip to content

Instantly share code, notes, and snippets.

@jsleeio
Last active December 26, 2022 19:57
Show Gist options
  • Save jsleeio/e5cbd42072bc6dc25924a2b0cf71ca91 to your computer and use it in GitHub Desktop.
Save jsleeio/e5cbd42072bc6dc25924a2b0cf71ca91 to your computer and use it in GitHub Desktop.
macOS scripted configuration with 'defaults'
#!/bin/bash
### @jsleeio, 2022
###
### diff the last two sets of defaults data dumped with read-all-domains.sh
function _die() {
echo "FATAL: $*" >&2
exit 1
}
cd "$HOME/.defaults_history" || _die "accessing defaults dump directory"
old=$(ls -1tr | tail -2 | head -1)
new=$(ls -1tr | tail -1)
[[ "$old" = "$new" ]] && _die "need at least two dumped default sets"
diff -Naur "$old" "$new"
#!/bin/bash
### @jsleeio, 2022
###
### export all accessible defaults to a new directory
function _die() {
echo "FATAL: $*" >&2
exit 1
}
function _list_domains() {
( defaults domains || _die "can't list domains" ; echo NSGlobalDomain ) \
| sed 's/,//g' \
| xargs -n1 basename \
| sort -n
}
function _setup_target_directory() {
local thisdir
thisdir="$HOME/.defaults_history/read.$(date +%s)"
mkdir -p "$thisdir" || _die "setting up target directory to dump defaults: $thisdir"
cd "$thisdir" || _die "accessing target directory: $thisdir"
echo "defaults will be written to $thisdir"
}
_setup_target_directory
for domain in $(_list_domains) ; do
echo "*** attempting $domain"
defaults read "$domain" > "$domain"
echo
done
#!/bin/bash
### @jsleeio, 2022
###
### set the basic bits I like in BetterSnapTool --- snapping disabled and
### Nethack-style keys (plus some extras) for moving windows around.
function _write_one_keybinding() {
# ref: https://shadowfile.inode.link/blog/2018/06/advanced-defaults1-usage/
local key="$1" keycode="$2" modifiers="$3" xml
xml="$(printf '<dict><key>keyCode</key><integer>%d</integer><key>modifiers</key><integer>%d</integer></dict>' "$keycode" "$modifiers")"
defaults write com.hegenberg.BetterSnapTool registeredHotkeys -dict-add "$key" "$xml"
}
function _write_keybindings() {
_write_one_keybinding 0 126 8395008
_write_one_keybinding 105 43 6400
_write_one_keybinding 106 47 6400
_write_one_keybinding 11 16 6400
_write_one_keybinding 12 32 6400
_write_one_keybinding 13 11 6400
_write_one_keybinding 14 45 6400
_write_one_keybinding 15 40 6400
_write_one_keybinding 16 38 6400
_write_one_keybinding 18 123 6400
_write_one_keybinding 19 33 6400
_write_one_keybinding 2 4 6400
_write_one_keybinding 20 30 6400
_write_one_keybinding 21 42 6400
_write_one_keybinding 4 37 6400
}
for f in snap{Bottom,Top,}{Left,Right} snapTop ; do
defaults write com.hegenberg.BetterSnapTool $f -int 0
done
defaults write com.hegenberg.BetterSnapTool launchOnStartup -int 1
# completely disable snap areas, we don't use them
defaults write com.hegenberg.BetterSnapTool BSTDisableSnapAreas -int 1
# don't prompt for appstore review
defaults write com.hegenberg.BetterSnapTool BSTAskedForReview -int 1
# configure our preferred keybindings
_write_keybindings
#!/bin/bash
### @jsleeio, 2022
###
### all the really juicy bits in iTerm2 are super annoying to change
### this way. Don't have the energy for it right now
defaults write com.googlecode.iterm2 DimBackgroundWindows -int 0
defaults write com.googlecode.iterm2 DimOnlyText -int 0
defaults write com.googlecode.iterm2 DisableFullscreenTransparency -int 1
defaults write com.googlecode.iterm2 HideScrollbar -int 1
defaults write com.googlecode.iterm2 SplitPaneDimmingAmount -float 0.09803682493932038
defaults write com.googlecode.iterm2 TabStyleWithAutomaticOption -int 6
defaults write com.googlecode.iterm2 UseBorder -int 0
defaults write com.googlecode.iterm2 SoundForEsc -int 0
#!/bin/bash
### @jsleeio, 2022
###
### set a bunch of things the way I like them in macOS
# fast keyboard repeat
defaults write NSGlobalDomain InitialKeyRepeat -int 15
defaults write NSGlobalDomain KeyRepeat -int 2
# automatic light/dark mode
defaults write NSGlobalDomain AppleInterfaceStyleSwitchesAutomatically -int 1
# correct hour time format
defaults write NSGlobalDomain AppleICUForce24HourTime -int 1
# choose a slightly-less-annoying beep noise
defaults write NSGlobalDomain com.apple.sound.beep.sound -string /System/Library/Sounds/Pop.aiff
# trackpad bits. Force click GTFO
defaults write NSGlobalDomain com.apple.trackpad.forceClick -int 0
defaults write com.apple.AppleMultitouchTrackpad ActuateDetents -int 0
defaults write com.apple.AppleMultitouchTrackpad ForceSuppressed -int 1
# hot corners
defaults write com.apple.dock wvous-tl-corner -int 1 # nothing
defaults write com.apple.dock wvous-tl-modifier -int 0 # no modifier key
defaults write com.apple.dock wvous-tr-corner -int 6 # don't lock screen
defaults write com.apple.dock wvous-tr-modifier -int 0 # no modifier key
defaults write com.apple.dock wvous-bl-corner -int 13 # lock screen
defaults write com.apple.dock wvous-bl-modifier -int 0 # no modifier key
defaults write com.apple.dock wvous-br-corner -int 1 # nothing
defaults write com.apple.dock wvous-br-modifier -int 0 # no modifier key
# dock
defaults write com.apple.dock autohide -int 1
defaults write com.apple.dock autohide-delay -float 0
defaults write com.apple.dock magnification -int 0
defaults write com.apple.dock minimize-to-application -int 1
defaults write com.apple.dock orientation -string right
defaults write com.apple.dock tilesize -int 128
defaults write com.apple.dock hide-mirror -bool true
defaults write com.apple.dock showhidden -bool true
# don't show desktop icons for volumes/media, I know where to find those
# in Finder if I want them
defaults write com.apple.finder ShowExternalHardDrivesOnDesktop -int 0
defaults write com.apple.finder ShowRemovableMediaOnDesktop -int 0
defaults write com.apple.finder ShowHardDrivesOnDesktop -int 0
# show all the files
defaults write com.apple.finder AppleShowAllFiles -int 1
# actually show where we are in Finder
defaults write com.apple.finder _FXShowPosixPathInTitle -int 1
# eliminate .DS_Store droppings on network volumes
defaults write com.apple.desktopservices DSDontWriteNetworkStores -int 0
# automatically expire trashed items after 30 days
defaults write com.apple.finder FXRemoveOldTrashItems -int 1
# always show the file suffixes! argh!
defaults write NSGlobalDomain AppleShowAllExtensions -int 1
# gtfo personalized advertising
defaults write com.apple.AdLib allowApplePersonalizedAdvertising -int 0
defaults write com.apple.AdLib allowIdentifierForAdvertising -int 0
# show safari developer menu
defaults write com.apple.Safari IncludeDevelopMenu -bool true
# cpu usage history in activity monitor icon
defaults write com.apple.ActivityMonitor IconType -int 6
# show outlines around toolbar buttons
defaults write com.apple.universalaccess showToolbarButtonShapes -int 1
# shake the mouse pointer to make it bigger
defaults write NSGlobalDomain CGDisableCursorLocationMagnification -int 1
pkill Dock
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment