Skip to main content

macOS

https://medium.com/@simpleandkind788/7-macos-tahoe-settings-you-should-turn-off-right-now-fed342f8a70e

NameCharacterkbdPhysical key
Command⊞ Windows
ControlCtrl
ShiftMayús
Option / AltAlt
EscapeEsc

Glyps

Advanced macOS Command-Line Tools - https://saurabhs.org/advanced-macos-commands

What prevents Mac to sleep

pmset -g assertions

See https://osxdaily.com/2012/07/11/mac-wont-sleep-heres-how-to-find-out-why-and-fix-it

Defaults

https://macos-defaults.com

defaults help
defaults domains
defaults domains | tr ',' '\n' # List one per line. Easier to read
defaults read com.apple.finder ShowPathbar # 1
defaults read-type com.apple.finder ShowPathbar # Type is boolean
defaults write com.apple.finder ShowPathbar -bool true

Backup:

defaults read > defaults
defaults read com.apple.finder > finder
defaults export com.apple.finder - > defaults.plist # XML plist, but only one domain

https://ss64.com/mac/defaults.html

If you change a default that belongs to a running application, the application won’t see the change and might even overwrite the default.

In general you should close an application before changing its defaults, in the case of Dock and Finder defaults - restart them after applying the default with the killall command (killall Dock, killall Finder).

https://pawelgrzybek.com/change-macos-user-preferences-via-command-line/

Examples:

Finder

defaults write com.apple.finder ShowPathbar -bool true

caffeinate - Prevent Mac from sleeping

Man page - https://ss64.com/osx/caffeinate.html

https://commandmasters.com/commands/caffeinate-osx/

caffeinate -i terraform apply -auto-approve
caffeinate -i ./scripts/server/create-aws-infrastructure.sh dev
caffeinate -u -t 3600 # Prevent display sleep for 1 hour
caffeinate -i -t 7200 # Prevent system sleep for 2 hours

If your script spawns background processes and exits early (rare), then you’d instead do:

caffeinate -i bash -c "./scripts/server/delete-aws-infrastructure.sh dev"

-i — prevent idle sleep

  • This is the one you usually want.
  • The Mac will not go to sleep due to user inactivity.
  • Allows display to turn off (saves screen, power).
  • The system stays fully awake and networking stays up.
  • Works on battery or AC power.

-s — prevent system sleep while on AC power

  • Only works while plugged into power.
  • The Mac will not enter system sleep at all.
  • More aggressive than -i.

Keyboard Shortcuts

Mac keyboard shortcuts

Cycle current application’s windows: + `

Character Viewer (emoji picker): + Ctrl + Space

Show/hide hidden files: + Shift + .

All my macOS keyboard shortcuts - https://www.jamieonkeys.dev/posts/keyboard-shortcuts - https://news.ycombinator.com/item?id=30876934

Add sleep shortcut

https://apple.stackexchange.com/a/431149/241238

Monterey: Preferències → Teclat → pestanya Dreceres → Dreceres de l'app. Ventura: Configuració → Teclat → Dreceres de teclat... → Dreceres de l'app. Afegir 2 dreceres noves amb nom 'Sleep' i 'Repòs' a ShiftAltQ. Haig de veure el shortcut ⌥⇧Q al menu del sistema.

Prevent ⌘+i to open the Mail app on Chrome

https://apple.stackexchange.com/questions/108060/how-to-prevent-command-i-command-shift-i-from-opening-mac-mail-when-in-browser

Ventura: Configuració → Teclat → Dreceres de teclat... → Dreceres de l'app. Clicar '+'. Al menú que s'obre seleccionar:

  • App: Google Chrome.
  • Títol de menú: ha de ser exactament "Envia l'enllaç per correu electrònic". És el que diu a Chrome → Fitxer → Comparteix.
  • Drecera de teclat: qualsevol cosa, per exemple ⌃⌥⇧⌘E.

DefaultKeyBinding.dict

{
"^u" = "deleteWordBackward:";
"^o" = "deleteWordForward:";
"^j" = "moveWordBackward:";
"^l" = "moveWordForward:";
}

Place this file in ~/Library/KeyBindings/ (create the folder if it doesn't exist yet).

Note that you need to restart the apps to take effect (eg run killall Finder to restart Finder, close and open Firefox etc.).

Examples:

kexts

Used by Little Snitch and Razer Synapse.

Are located in /Library/Extensions/.

Free up disk space

tip

Per trobar fitxers grans fer:

  • Clicar l'escriptori i prémer Command + F.
  • S'obrirà una finestra del finder. A "Buscar a:" seleccionar "Aquest Mac"
  • Seleccionar:
    • Mida de l'arxiu
    • és superior a
    • 100
    • MB

Això mostra fitxers com Docker.raw que no apareixen a "Sobre aquest Mac" → Emmagatzematge → Gestionar... Atenció: el fitxer Docker.raw no té realment la mida que diu el Mac (64 GB!), cal fer du -h ~/Library/Containers/com.docker.docker/Data/vms/0/data/Docker.raw per veure la mida real - source.

  • (This frees plenty GBs.) Android emulators, system images, SDKs, build tools, NDK etcetera:
    • The Android virtual devices are stored at ~/.android/avd.
    • To get rid of Android emulators, open Android Studio → Device Manager and delete them.
    • To get rid of Android system images, SDKs and other stuff, open Android Studio → SDK Manager. (There are various ways to open it, eg Settings → Languages & Frameworks → Android SDK). Once thee, check the checkbox 'Show package details'. Then uninstall everything possible like the NDK, emulator System Images, SDKs etcetera.
  • Delete node_modules folders with npkill:
    • npx npkill@latest --directory ~/Programming.
    • npx npkill@latest --directory ~/Webs.
  • Delete yarn cache: yarn cache clean - docs. Can be +20 GB.
  • Delete gradle cache (~/.gradle/caches): rm -rf ~/.gradle/caches. See How to clear gradle cache?.
    • The whole ~/.gradle folder is still big though (~600 MB). You can delete it if you don't need cached dependencies or wrapper files. Gradle will recreate this folder and re-download dependencies as needed when you build projects again. Deleting it may slow down the next build due to re-downloading.
  • Delete npm cache (~/.npm/_cacache): npm cache clean --force. Not sure if doing this is necessary, see Why and how to clear npm cache. You can check the cache size with npm cache verify.
  • Delete Carthage cache (can be 2-3 GB): rm -rf ~/Library/Caches/org.carthage.CarthageKit source
  • Delete build folders: find . -type d -name "build" -exec rm -rf {} +.
  • Delete Python venv and .venv folders:
    • find . -type d -name "venv" -exec rm -rf {} +
    • find . -type d -name ".venv" -exec rm -rf {} +
  • Delete unused Node.js versions. Run fnm list. They are stored at ~/.local/share/fnm/node-versions.
  • Delete unused Ruby versions. Run rbenv versions. They are stored at ~/.rbenv/versions.
  • Delete .terraform folders. The aws provider is 580 MB. See instructions
  • Xcode
  • JetBrains IDEs, delete old versions: Help → Delete Leftover IDE Directories…
    • JetBrains IDEs are located at ~/Library/Application Support/JetBrains (cd ~/Library/Application\ Support/JetBrains).
    • There are also really big files at ~/Library/Caches/JetBrains.
    • Directories are listed at the uninstall instructions: https://www.jetbrains.com/help/idea/uninstall.html#macos.
    • Android Studio is located at ~/Library/Application Support/Google (cd ~/Library/Application\ Support/Google).
  • Clear ~/Library/Caches/Google. Contains data of old versions of Android Studio.
  • Docker:
    • Docs: Prune unused Docker objects: https://docs.docker.com/config/pruning.
    • Remove dangling images (images with <none> in docker image ls): docker image prune (docs)
      • IMPORTANT: be careful with docker image prune -a because it deletes plenty of stuff, eg it has deleted all images shown by docker image ls, not only the ones with <none>! It says WARNING! This will remove all images without at least one container associated to them..
    • Pune everything: docker system prune. This removes all stopped containers, all networks not used by at least one container, all dangling images and all build cache.
    • You can adjust the "Disk usage limit" at the Docker Desktop Settings → Resources.
    • The Mac may say that the Docker.raw file is (eg) 64 GB, but this is not true. To check the actual size of the Docker.raw file use du -h ~/Library/Containers/com.docker.docker/Data/vms/0/data/Docker.raw - source.
  • Anar a ~/Library/Application Support i esborrar programes antics.
  • Esborrar fitxers grans: Sobre aquest Mac → Emmagatzematge → Gestionar...
  • Telegram: esborrar la memòria cau (pot tenir 1 GB). Es fa a Configuració → Dades i emmagatzematge → Ús de l'emmagatzematge
  • Firefox: esborrar dades del lloc (pot ser 3 GB). Anar a Preferències → Privadesa i seguretat → Gestiona les dades... S'ordenen per mida. Cal apretar Delete a cada Lloc i després 'Desa els canvis' (sinó no esborra). Esborrar les que fa més d'un any que es van fer servir ('Darrer ús').
  • Brew:
    • brew autoremove: uninstall formulae that were only installed as a dependency of another formula and are now no longer needed.
    • brew cleanup: usually not necessary, but sometimes frees space.
  • Spotify: esborrar la "Memòria cau" a les Preferències (uns 500 MB).
  • Find file duplicates:

https://cleanmymac.com

Port 5000 used

Si tens aquest error:

Error: listen EADDRINUSE: address already in use :::5000

Si fas lsof -i tcp:5000 diu:

COMMAND   PID   USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
ControlCe 971 albert 9u IPv4 0x82f98b9c1d6f8cd3 0t0 TCP *:commplex-main (LISTEN)
ControlCe 971 albert 11u IPv6 0x4e61d39e72bdbfc6 0t0 TCP *:commplex-main (LISTEN)

Cal anar a Configuració del Sistema → General → AirDrop i Handoff i desactivar el switch "Receptor AirPlay".

Veure: