|
1 | | -# osx-optimizer |
| 1 | +# OSX-Optimizer |
2 | 2 | OSX Optimizer: Optimize MacOS - Shell scripts to speed up your mac boot time, accelerate loading, and prevent unnecessary throttling. |
| 3 | + |
| 4 | +macOS can be heavily modified using the `defaults` command. In fact, almost every option is accessible via `defaults`. |
| 5 | + |
| 6 | +A great way to see what ticking and unticking a box in the Settings App is by using: |
| 7 | + |
| 8 | +```bash |
| 9 | +defaults read > defaults.pre.txt |
| 10 | + |
| 11 | +# *make a change in Settings* |
| 12 | + |
| 13 | +defaults read > defaults.post.txt |
| 14 | + |
| 15 | +diff defaults.pre.txt defaults.post.txt |
| 16 | +``` |
| 17 | + |
| 18 | +# OSX Optimizations |
| 19 | + |
| 20 | +Below you will find extremely good optimizers, particularly for virtual machines. |
| 21 | + |
| 22 | +Some of the commands are dangerous from a remote access perspective, but they will greatly optimize your VM. |
| 23 | + |
| 24 | + |
| 25 | +## Skip the GUI login screen (at your own risk!) |
| 26 | +```bash |
| 27 | +defaults write com.apple.loginwindow autoLoginUser -bool true |
| 28 | +``` |
| 29 | + |
| 30 | +User accounts and root/administrator have different `defaults` |
| 31 | + |
| 32 | +## Disable spotlight indexing on macOS to heavily speed up Virual Instances. |
| 33 | + |
| 34 | +```bash |
| 35 | +# massively increase virtualized macOS by disabling spotlight. |
| 36 | +sudo mdutil -i off -a |
| 37 | + |
| 38 | +# since you can't use spotlight to find apps, you can renable with |
| 39 | +# sudo mdutil -i on -a |
| 40 | + |
| 41 | +``` |
| 42 | + |
| 43 | +## Disable heavy login screen wallpaper |
| 44 | + |
| 45 | +```bash |
| 46 | +sudo defaults write /Library/Preferences/com.apple.loginwindow DesktopPicture "" |
| 47 | +``` |
| 48 | + |
| 49 | +## Enable multi-sessions |
| 50 | + |
| 51 | +```bash |
| 52 | +sudo /usr/bin/defaults write .GlobalPreferences MultipleSessionsEnabled -bool TRUE |
| 53 | + |
| 54 | +defaults write "Apple Global Domain" MultipleSessionsEnabled -bool true |
| 55 | +``` |
| 56 | + |
| 57 | +## Disable updates (at your own risk!) |
| 58 | +This will prevent macOS from downloading huge updates, filling up your disk space. |
| 59 | + |
| 60 | +Disabling updates heavily speeds up virtualized macOS because the qcow2 image does not grow out of proportion. |
| 61 | + |
| 62 | +```bash |
| 63 | +# as roots |
| 64 | +sudo su |
| 65 | +defaults write /Library/Preferences/com.apple.SoftwareUpdate AutomaticDownload -bool false |
| 66 | +defaults write com.apple.SoftwareUpdate AutomaticCheckEnabled -bool false |
| 67 | +defaults write com.apple.commerce AutoUpdate -bool false |
| 68 | +defaults write com.apple.commerce AutoUpdateRestartRequired -bool false |
| 69 | +defaults write com.apple.SoftwareUpdate ConfigDataInstall -int 0 |
| 70 | +defaults write com.apple.SoftwareUpdate CriticalUpdateInstall -int 0 |
| 71 | +defaults write com.apple.SoftwareUpdate ScheduleFrequency -int 0 |
| 72 | +defaults write com.apple.SoftwareUpdate AutomaticDownload -int 0 |
| 73 | +``` |
| 74 | + |
| 75 | +## Enable `osascript` over SSH automatically without **sshd-keygen warning** and **full disk access** |
| 76 | + |
| 77 | +```bash |
| 78 | + |
| 79 | +defaults write com.apple.universalaccessAuthWarning /System/Applications/Utilities/Terminal.app -bool true |
| 80 | +defaults write com.apple.universalaccessAuthWarning /usr/libexec -bool true |
| 81 | +defaults write com.apple.universalaccessAuthWarning /usr/libexec/sshd-keygen-wrapper -bool true |
| 82 | +defaults write com.apple.universalaccessAuthWarning com.apple.Messages -bool true |
| 83 | +defaults write com.apple.universalaccessAuthWarning com.apple.Terminal -bool true |
| 84 | + |
| 85 | +``` |
| 86 | + |
| 87 | +## Disable screen locking |
| 88 | + |
| 89 | +```bash |
| 90 | +defaults write com.apple.loginwindow DisableScreenLock -bool true |
| 91 | +``` |
| 92 | + |
| 93 | +## Show a lighter username/password prompt instead of a list of all the users |
| 94 | + |
| 95 | +```bash |
| 96 | +defaults write /Library/Preferences/com.apple.loginwindow.plist SHOWFULLNAME -bool true |
| 97 | +defaults write com.apple.loginwindow AllowList -string '*' |
| 98 | + |
| 99 | +``` |
| 100 | + |
| 101 | +## Disable saving the application state on shutdown |
| 102 | + |
| 103 | +This speeds up boot as the session state (currently opened apps) are not running when you reboot. |
| 104 | + |
| 105 | +This may be slower for you depending on what you are doing. |
| 106 | + |
| 107 | +```bash |
| 108 | +defaults write com.apple.loginwindow TALLogoutSavesState -bool false |
| 109 | +``` |
| 110 | + |
| 111 | +Enable AnyDesk automatically |
| 112 | + |
| 113 | +```bash |
| 114 | + |
| 115 | +defaults write com.apple.universalaccessAuthWarning "/Applications/AnyDesk.app" -bool true |
| 116 | +defaults write com.apple.universalaccessAuthWarning "/Applications/AnyDesk.app/Contents/MacOS/AnyDesk" -bool true |
| 117 | +defaults write com.apple.universalaccessAuthWarning "3::/Applications" -bool true |
| 118 | +defaults write com.apple.universalaccessAuthWarning "3::/Applications/AnyDesk.app" -bool true |
| 119 | +defaults write com.apple.universalaccessAuthWarning "com.philandro.anydesk" -bool true |
| 120 | + |
| 121 | +``` |
| 122 | + |
| 123 | +## Enable remote access (at your own risk!) |
| 124 | + |
| 125 | +```bash |
| 126 | +sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart \ |
| 127 | + -activate \ |
| 128 | + -configure \ |
| 129 | + -access \ |
| 130 | + -off \ |
| 131 | + -restart \ |
| 132 | + -agent \ |
| 133 | + -privs \ |
| 134 | + -all \ |
| 135 | + -allowAccessFor -allUsers |
| 136 | +``` |
| 137 | + |
| 138 | + |
| 139 | + |
| 140 | + |
| 141 | + |
| 142 | +# EXTREMELY INSECURE METHODS (at your own risk!) |
| 143 | + |
| 144 | +These macOS optimizations should only be used in CI/CD, behind a VPN, and with no external connectivity. |
| 145 | + |
| 146 | +This is not a warning, it is absolutely essential, or anyone can just SSH into the remote mac. |
| 147 | + |
| 148 | +If you do any of the below commands on a remote server, you will |
| 149 | + |
| 150 | +## Disable passwords globally |
| 151 | + |
| 152 | +- Everyone is now root |
| 153 | +- No need to type passwords |
| 154 | +- SSH login just hit enter for password |
| 155 | + |
| 156 | +As root: |
| 157 | + |
| 158 | +```bash |
| 159 | +sudo su |
| 160 | +# nuke pam |
| 161 | +for PAM_FILE in /etc/pam.d/*; do |
| 162 | + sed -i -e s/required/optional/g "${PAM_FILE}" |
| 163 | + sed -i -e s/sufficient/optional/g "${PAM_FILE}" |
| 164 | +done |
| 165 | +``` |
| 166 | + |
| 167 | + |
| 168 | + |
| 169 | +sudo killall Finder || true |
| 170 | +sudo killall Dock || true |
| 171 | +sudo killall mds |
| 172 | + |
| 173 | + |
| 174 | +## Make everyone a sudoer |
| 175 | + |
| 176 | +```bash |
| 177 | +cd /Users |
| 178 | +# add everyone to sudoers and import the control center plist |
| 179 | +for REAL_NAME in *; do |
| 180 | + echo "${REAL_NAME}" |
| 181 | + tee "/etc/sudoers.d/${REAL_NAME}" <<< "${REAL_NAME} ALL=(ALL) NOPASSWD: ALL" |
| 182 | + # sudo -u "${REAL_NAME}" defaults write -globalDomain NSUserKeyEquivalents -dict-add "Save as PDF\\U2026" "@\$p"; |
| 183 | + sudo -u "${REAL_NAME}" sudo mdutil -i off -a |
| 184 | + # sudo -u "${REAL_NAME}" defaults import com.apple.controlcenter /tmp/com.apple.controlcenter.plist |
| 185 | + # sudo -u "${REAL_NAME}" defaults write "/Users/${REAL_NAME}/Library/Preferences/.GlobalPreferences MultipleSessionEnabled" -bool 'YES' |
| 186 | + # sudo -u mdutil -i off -a |
| 187 | + # sudo dscl . -create "/Users/${REAL_NAME}" UserShell "${USERSHELL}" |
| 188 | + sudo -u "${REAL_NAME}" "whoami" |
| 189 | +done |
| 190 | +#############################3 |
| 191 | + |
| 192 | +``` |
| 193 | + |
| 194 | + |
| 195 | +# Disable apps from going to sleep at all |
| 196 | +This command will prevent applications from sleeping, completely in the background. |
| 197 | + |
| 198 | +You can verify this using the `top` command and an App should never go into `sleeping` state. |
| 199 | + |
| 200 | +This increases RAM usage, but means your apps, like Xcode, will spring into action. |
| 201 | + |
| 202 | +```bash |
| 203 | +sudo -u "${REAL_NAME}" sudo defaults write NSGlobalDomain NSAppSleepDisabled -bool YES |
| 204 | +``` |
| 205 | + |
| 206 | + |
| 207 | + |
0 commit comments