OSX Optimizer: Optimize MacOS - Shell scripts to speed up your mac boot time, accelerate loading, and prevent unnecessary throttling.
macOS can be heavily modified using the defaults
command. In fact, almost every option is accessible via defaults
.
A great way to see what ticking and unticking a box in the Settings App is by using:
defaults read > defaults.pre.txt
# *make a change in Settings*
defaults read > defaults.post.txt
diff defaults.pre.txt defaults.post.txt
Below you will find extremely good optimizers, particularly for virtual machines.
Some of the commands are dangerous from a remote access perspective, but they will greatly optimize your VM.
defaults write com.apple.loginwindow autoLoginUser -bool true
User accounts and root/administrator have different defaults
# massively increase virtualized macOS by disabling spotlight.
sudo mdutil -i off -a
# since you can't use spotlight to find apps, you can renable with
# sudo mdutil -i on -a
Turn on performance mode to dedicate additional system resources for server applications.
Details: https://support.apple.com/en-us/HT202528
# check if enabled (should contain `serverperfmode=1`)
nvram boot-args
# turn on
sudo nvram boot-args="serverperfmode=1 $(nvram boot-args 2>/dev/null | cut -f 2-)"
# turn off
sudo nvram boot-args="$(nvram boot-args 2>/dev/null | sed -e $'s/boot-args\t//;s/serverperfmode=1//')"
sudo defaults write /Library/Preferences/com.apple.loginwindow DesktopPicture ""
defaults write com.apple.Accessibility DifferentiateWithoutColor -int 1
defaults write com.apple.Accessibility ReduceMotionEnabled -int 1
defaults write com.apple.universalaccess reduceMotion -int 1
defaults write com.apple.universalaccess reduceTransparency -int 1
defaults write com.apple.Accessibility ReduceMotionEnabled -int 1
sudo /usr/bin/defaults write .GlobalPreferences MultipleSessionsEnabled -bool TRUE
defaults write "Apple Global Domain" MultipleSessionsEnabled -bool true
This will prevent macOS from downloading huge updates, filling up your disk space.
Disabling updates heavily speeds up virtualized macOS because the qcow2 image does not grow out of proportion.
# as roots
sudo su
defaults write /Library/Preferences/com.apple.SoftwareUpdate AutomaticDownload -bool false
defaults write com.apple.SoftwareUpdate AutomaticCheckEnabled -bool false
defaults write com.apple.commerce AutoUpdate -bool false
defaults write com.apple.commerce AutoUpdateRestartRequired -bool false
defaults write com.apple.SoftwareUpdate ConfigDataInstall -int 0
defaults write com.apple.SoftwareUpdate CriticalUpdateInstall -int 0
defaults write com.apple.SoftwareUpdate ScheduleFrequency -int 0
defaults write com.apple.SoftwareUpdate AutomaticDownload -int 0
defaults write com.apple.universalaccessAuthWarning /System/Applications/Utilities/Terminal.app -bool true
defaults write com.apple.universalaccessAuthWarning /usr/libexec -bool true
defaults write com.apple.universalaccessAuthWarning /usr/libexec/sshd-keygen-wrapper -bool true
defaults write com.apple.universalaccessAuthWarning com.apple.Messages -bool true
defaults write com.apple.universalaccessAuthWarning com.apple.Terminal -bool true
defaults write com.apple.loginwindow DisableScreenLock -bool true
defaults write /Library/Preferences/com.apple.loginwindow.plist SHOWFULLNAME -bool true
defaults write com.apple.loginwindow AllowList -string '*'
This speeds up boot as the session state (currently opened apps) are not running when you reboot.
This may be slower for you depending on what you are doing.
defaults write com.apple.loginwindow TALLogoutSavesState -bool false
Enable AnyDesk automatically
defaults write com.apple.universalaccessAuthWarning "/Applications/AnyDesk.app" -bool true
defaults write com.apple.universalaccessAuthWarning "/Applications/AnyDesk.app/Contents/MacOS/AnyDesk" -bool true
defaults write com.apple.universalaccessAuthWarning "3::/Applications" -bool true
defaults write com.apple.universalaccessAuthWarning "3::/Applications/AnyDesk.app" -bool true
defaults write com.apple.universalaccessAuthWarning "com.philandro.anydesk" -bool true
sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart \
-activate \
-configure \
-access \
-off \
-restart \
-agent \
-privs \
-all \
-allowAccessFor -allUsers
These macOS optimizations should only be used in CI/CD, behind a VPN, and with no external connectivity.
This is not a warning, it is absolutely essential, or anyone can just SSH into the remote mac.
If you do any of the below commands on a remote server, you will
- Everyone is now root
- No need to type passwords
- SSH login just hit enter for password
As root:
sudo su
# nuke pam
for PAM_FILE in /etc/pam.d/*; do
sed -i -e s/required/optional/g "${PAM_FILE}"
sed -i -e s/sufficient/optional/g "${PAM_FILE}"
done
sudo killall Finder || true sudo killall Dock || true sudo killall mds
cd /Users
# add everyone to sudoers and import the control center plist
for REAL_NAME in *; do
echo "${REAL_NAME}"
tee "/etc/sudoers.d/${REAL_NAME}" <<< "${REAL_NAME} ALL=(ALL) NOPASSWD: ALL"
# sudo -u "${REAL_NAME}" defaults write -globalDomain NSUserKeyEquivalents -dict-add "Save as PDF\\U2026" "@\$p";
sudo -u "${REAL_NAME}" sudo mdutil -i off -a
# sudo -u "${REAL_NAME}" defaults import com.apple.controlcenter /tmp/com.apple.controlcenter.plist
# sudo -u "${REAL_NAME}" defaults write "/Users/${REAL_NAME}/Library/Preferences/.GlobalPreferences MultipleSessionEnabled" -bool 'YES'
# sudo -u mdutil -i off -a
# sudo dscl . -create "/Users/${REAL_NAME}" UserShell "${USERSHELL}"
sudo -u "${REAL_NAME}" "whoami"
done
#############################3
This command will prevent applications from sleeping, completely in the background.
You can verify this using the top
command and an App should never go into sleeping
state.
This increases RAM usage, but means your apps, like Xcode, will spring into action.
sudo -u "${REAL_NAME}" sudo defaults write NSGlobalDomain NSAppSleepDisabled -bool YES