mirror of
https://gitea.com/mcereda/oam.git
synced 2026-02-14 07:44:25 +00:00
8.7 KiB
8.7 KiB
Mac OS X
- TL;DR
- Xcode CLI tools
- Hidden settings
- Resize an image from CLI
- Boot keys cheatsheet
- Update the OS from CLI
- Keychain access from CLI
- Sources
TL;DR
# Install a .pkg file from CLI.
# 'target' needs to be a device, not a path.
installer -pkg /path/to/non-root-package.pkg -target CurrentUserHomeDirectory
sudo installer -pkg /path/to/root-needed-package.pkg -target /
# Install Xcode CLI tools.
xcode-select --install
# Show Xcode tools's path.
xcode-select -p
# Remove Xcode tools.
sudo rm -rf $(xcode-select -p)
# List all available updates.
softwareupdate --list --all
# Install all recommended updates, agreeing to software license agreement
# without interaction, and automatically restart if required.
softwareupdate --install --recommended --restart --agree-to-license
# Download (but not install) recommended updates.
softwareupdate --download --recommended
# Add a password to the default keychain.
# The password needs to be left last.
security add-generic-password -a johnny -s github -w 'b.good'
# Add a password to the default keychain giving it some optional data.
security add-generic-password -a johnny -s github -l work \
-j 'my key for work' -w 'b.good'
# Update a passwork value.
security add-generic-password -a johnny -s github -l work -U -w 'new-pass'
# Print a password to stdout.
security find-generic-password -w -a johnny -s github
security find-generic-password -w -l work
security find-generic-password -w -l work -s github
# Delete a password from the default keychain.
security delete-generic-password -a johnny -s github
# Get the host's bonjour name.
scutil --get LocalHostName
/usr/libexec/PlistBuddy -c "Print :System:Network:HostNames:LocalHostName" \
/Library/Preferences/SystemConfiguration/preferences.plist
# Get the host's netbios name.
defaults read /Library/Preferences/SystemConfiguration/com.apple.smb.server NetBIOSName
/usr/libexec/PlistBuddy -c "Print :NetBIOSName" \
/Library/Preferences/SystemConfiguration/com.apple.smb.server.plist
# Get the host's computer name.
scutil --get ComputerName
/usr/libexec/PlistBuddy -c "Print :System:System:ComputerName" \
/Library/Preferences/SystemConfiguration/preferences.plist
Xcode CLI tools
xcode-select --install
The tools will be installed into /Library/Developer/CommandLineTools by default, with the binaries being available at $(xcode-select -p)/usr/bin/.
Headless installation
# Force the `softwareupdate` utility to list the Command Line Tools.
touch /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress
# Get their label.
CLI_TOOLS_LABEL="$(/usr/sbin/softwareupdate -l \
| grep -B 1 -E 'Command Line Tools' \
| awk -F'*' '/^ *\\*/ {print $2}' \
| sed -e 's/^ *Label: //' -e 's/^ *//' \
| sort -V \
| tail -n1)"
# Install them.
/usr/sbin/softwareupdate -i --agree-to-license "$CLI_TOOLS_LABEL"
Removal
sudo rm -rf $(xcode-select -p)
sudo rm -rf /Library/Developer/CommandLineTools
Upgrade
See How to update Xcode from command line for details.
# Remove and reinstall.
sudo rm -rf $(xcode-select -p)
xcode-select --install
Hidden settings
Note: once set something, you'll probably need to restart the dock with
killall Dock
# Show hidden apps indicators in the dock.
defaults write com.apple.dock showhidden -bool TRUE
# Reset changes to the dock.
defaults delete com.apple.dock
# Change the number of columns and rows in the springboard.
defaults write com.apple.dock springboard-columns -int 9
defaults write com.apple.dock springboard-rows -int 7
# Reset changes to the launchpad.
defaults delete com.apple.dock springboard-rows
defaults delete com.apple.dock springboard-columns
defaults write com.apple.dock ResetLaunchPad -bool TRUE
# Force Finder to always display hidden files.
defaults write com.apple.finder AppleShowAllFiles TRUE
Resize an image from CLI
# Retain ratio.
# Save as different file.
sips -Z 1000 -o resized.jpg IMG_20190527_013903.jpg
Boot keys cheatsheet
Only available on Intel based Macs.
To use any of these key combinations, press and hold the keys immediately after pressing the power button to turn on your Mac, or after your Mac begins to restart. Keep holding until the described behavior occurs.
| Combination | Behaviour |
|---|---|
⌥ Option or Alt |
Start to Startup Manager, which allows you to choose other available startup disks or volumes. If your Mac is using a firmware password, you're prompted to enter the password |
⌥ Option + ⌘ Command + P + R |
Reset the NVRAM or PRAM. If your Mac is using a firmware password, it ignores this key combination or starts up from Recovery |
⇧ Shift |
Start in safe mode. Disabled when using a firmware password |
⌘ Command + R |
Start from the built-in Recovery system |
⌥ Option + ⌘ Command + R or ⇧ Shift + ⌥ Option + ⌘ Command + R |
Start from Recovery over the Internet. It installs different versions of macOS, depending on the key combination you use while starting up. If your Mac is using a firmware password, you're prompted to enter the password |
⏏ Eject or F12 or mouse button or trackpad button |
Eject a removable media, such as an optical disc. Disabled when using a firmware password |
T |
Start in target disk mode. Disabled when using a firmware password |
⌘ Command + V |
Start in verbose mode. Disabled when using a firmware password |
D |
Start to Apple Diagnostics |
⌥ Option + D |
Start to Apple Diagnostics over the Internet. Disabled when using a firmware password |
N |
Start from a NetBoot server, if your Mac supports network startup volumes. Disabled when using a firmware password |
⌥ Option + N |
Start from a NetBoot server and use the default boot image on it. Disabled when using a firmware password |
⌘ Command + S |
Start in single-user mode. Disabled in macOS Mojave or later, or when using a firmware password |
Update the OS from CLI
# List all available updates.
softwareupdate --list --all
# Install all recommended updates.
# Agree to software license agreement without interaction.
# Automatically restart if required.
softwareupdate --install --recommended --restart --agree-to-license
# Download (but not install) recommended updates.
softwareupdate --download --recommended
Keychain access from CLI
Save a password with the following settings:
- user (a.k.a. account):
johnny - password:
b.good - service name:
github - [optional] entry name (a.k.a. label):
work; if not given, the service name will be used - [optional] comment:
my key for work; if not given, it will be left blank
The password's value needs to be given last.
# Add the password to the default keychain.
security add-generic-password -a johnny -s github -w 'b.good'
# Also give it some optional data.
security add-generic-password -a johnny -s github -l work \
-j 'my key for work' -w 'b.good'
# Update the passwork value.
security add-generic-password -a johnny -s github -l work -U -w 'new-pass'
# Print the above password to stdout.
security find-generic-password -w -a johnny -s github
security find-generic-password -w -l work
security find-generic-password -w -l work -s github
# Delete it.
security delete-generic-password -a johnny -s github