The best laptop money can buy:
https://www.apple.com/uk/macbook-pro/
If you don't have an M3 Pro / Max - you're missing out on an excellent (but overpriced) machine.
On balance of price vs performance the Macbook Air M3 is excellent, and even thinner and lighter than the Macbook Pro - a real joy to use. Even when you're using more RAM than the physical 16GB max and swapping, the performance is still so good you don't notice significant performance degradation for most usage, even when using heavyweight IDEs like IntelliJ.
- WARNING: Battery Life
- Terminal
- Homebrew - Package Management
- Activity Monitor
- Stats Bar
- Rearrange Status Bar Icons
- Reducing Desktop Workspaces
- Raycast
- Commands
- Search for or open anything
- Open URL from Terminal output
- Open
- Clipboard
- Screenshots
- Flush the DNS Cache
- Set DNS Servers
- Set DNS Search Domain
- Set Hostname
- Get Current Wifi Network Name
- Get Current Wifi Network Password
- List all Configured Wifi Networks
- Say - text-to-speech
- Finding Files - Spotlight Search and Index Management
- Launchctl
- Disk Management
- Service Management
- Binaries Debugging
- Creating Bootable CDs & USBs from ISOs
Within a few weeks of digitial nomadding working on beds with my laptop on the bed cover, I had degraded the battery of my new Macbook Pro M3 Max by 85%.
Charging through the USB port off a portable power bank also seemed to heat up the machine and deteriorate the battery by another couple percent after just half an hour.
This screenshot from Stats Bar shows why - it's using only Efficiency Cores rather than Performance Cores:
This is where you should be spending your life if you're a techie, with a browser to supplement referencing documentation.
$COLUMNS
- 179 column width on my MacBook Pro 13" terminal
- 204 on my MacBook Pro Retina 15" terminal
- 215 on my Macbook Pro M3 2023 terminal - resolution gets better over time
The best most widely used package manager for Mac.
See brew.md for how to use it and great package lists I've spent years discovering and building up.
See your CPU, RAM, Disk, Network and Energy usage of applications.
Sorting by CPU and RAM descending on their tabs is usually your first port of call.
To open Activity Monitor you can type Cmd-Space
to open Spotlight search bar and the start typing Activity Monitor
to find it and hit enter to open it.
On the command line you can also just run this:
open -a "Activity Monitor"
Stats gives many nice toolbar stats on your Mac's performance for CPU, GPU, RAM, Disk, Network and Battery.
Battery even tells you:
- time to discharge
- time to charge
- number of cycles (although this one I'm sure is only since installation of Stats)
- battery health
- which apps which are consuming a lot of energy for you to kill them if you're not needing them, helping your battery life when on the move
Now 14" Macbook Pros are powerful enough, but the screen space is very limited and you lose the top middle for the camera you end up losing icons behind the camera portion of the screen.
Rearrange your icons to put the most important and frequently used icons to the left while leaving icons you rarely click on like Google Drive to the left to be pushed underneath the camera.
To rearrange icons:
Cmd
+ Click + drag each icon to where you want it
If like me, you hate the time lost in graphics sliding effect from one desktop workspace to another, especially caused
by apps like Windows Virtual Desktop in Remote Desktop opening to full screen, and just prefer good old fashioned
Cmd
-Tab
, then you can remove the extra workspaces as
described here
by pressing F3 and then hovering on and clicking the X to delete the extra workspaces.
Unfortunately, Remote Desktop still seems to slide and send to fullscreen in another temporary desktop workspace.
Shortcut to everything - install and then hit Option
+ Space
to bring it up.
A list of commands is provided at https://ss64.com/mac/.
Cmd
-Space
- opens Spotlight search to auto-complete and open anything quickly.
Cmd
+ Click on the URL.
Open a file / folder / URL / Application. Use -a
to select which app to use to open it.
Use -e
to edit the file in TextEdit.
open https://google.com
open .
open file.jpg
You can also drag to the Terminal to paste a file or directory's path, or right-click copy and paste into the terminal to get its path on your command line.
open -a "SQLDeveloper.app"
Copy from stdin to clipboard:
pbcopy < input.txt
Paste from clipboard to stdout:
pbpaste > output.txt
Cmd
+ Shift
+ 3
Switches to a cross-hair to drag to what you want to screenshot.
Cmd
+ Shift
+ 4
in the Utilities folder is easy to use:
open /System/Applications/Utilities/Screenshot.app
You may be prompted to allow Terminal to record the screen under Privacy & Security
-> Screen Recording
the first
time - it'll tell you that you have to restart the Terminal, but it worked for me without a restart.
Switches to select window to capture:
screencapture -W /tmp/screenshot.png
Interactive mode with full toolbar, same as the Screenshot.app
:
screencapture -i -U /tmp/screenshot.png
Video recording mode for 10 seconds (without -V
it will record until you Ctrl
-c
it):
screencapture -v -V 10 /tmp/videocapture.mp4
So many great options from delayed screenshots, copy to clipboard, open in Preview, capture a coordinate rectangle (great for automation!), see:
screencapture --help
dscacheutil -flushcache
sudo killall -HUP mDNSResponder
Sometimes you want to use public DNS servers for better performance than the local DHCP given ones:
sudo networksetup -setdnsservers en0 4.2.2.1 4.2.2.2
To set back to DHCP DNS servers, just clear the list:
sudo networksetup -setdnsservers en0 "Empty"
In DevOps-Bash-tools the shell has a function dhcpdns
to do this for all network
interfaces and remove the DNS search domains since you should inherit them from DHCP and not leak those FQDN
searches to the internet if on public networks.
sudo networksetup -setsearchdomains en0 mydomain.com
In DevOps-Bash-tools the shell has a function set_dns
to do this for all network interfaces to
make this easier.
You should see these search domains appear in the class unix file /etc/resolv.conf
managed by apple networking.
To remove DNS search domains:
sudo networksetup -setsearchdomains en0 "Empty"
or clear_dns_search
function in DevOps-Bash-tools to do this for all interfaces.
hostname=whitestar
sudo hostname "$hostname"
sudo scutil --set HostName "$hostname"
sudo scutil --set ComputerName "$hostname"
sudo scutil --set LocalHostName "$hostname"
scutil --get HostName
scutil --get ComputerName
scutil --get LocalHostName
networksetup -getairportnetwork en0 | awk -F': ' '{print $2}'
Prompts with a UI pop-up for administrative access to the system's keychain (sudo
doesn't prevent this unfortunately):
security find-generic-password -g -w -D "AirPort network password" \
-a "$(networksetup -getairportnetwork en0 |
awk -F': ' '{print $2}')"
networksetup -listpreferredwirelessnetworks en0 |
sed '/Preferred networks on/d;
s/^[[:space:]]*//' |
sort -f
Make your Mac speak.
I used this to impress my kids, or even send a message from my loft study to my living room computer
by running say
over an SSH login to the computer downstairs for them to hear!
say "Daddy is the greatest"
You can also pipe in text:
echo "Daddy is the greatest" | say
Try different voices, list them like this:
say -v ?
Speak from a text file and save it to an audio file:
say -f words.txt -o myaudioclip.aiff
The equivalent of locate
on Linux, uses the Spotlight index:
mdfind [-onlyin /path/to/directory] [-name "$filename"] "$term"
Erase and rebuild the Spotlight index:
mdutil -E
Enable / disable Spotlight indexing for a given volume or entirely:
mdutil -i
This accesses launchd
, Mac's init script equivalent.
See which launchd
scripts are loaded:
launchctl list
Stop and unload script, add -w
to remove it from the boot sequence:
sudo launchctl unload [path/to/script]
Launch scripts are found in the following locations:
~/Library/LaunchAgents
/Library/LaunchAgents
/Library/LaunchDaemons
/System/Library/LaunchAgents
/System/Library/LaunchDaemons
Blog post on cool things launchd can do, like watching and executing on files that are dropped into directories.
Using graphical Disk Utility is easiest:
open /System/Applications/Utilities/Disk\ Utility.app
Great tutorial:
Part 1 - List, Verify, Repair, Rename, Erase volumes
Part 2 - Partition, Format, Split / Merge Partitions
Part 3 - Create .dmg
disk images from a Volume / Folder, Encrypted Disk Image, Resize Image, Restore Image
diskutil list
diskutil mount
and diskutil mountDisk
are the same
diskutil mount /dev/disk4s2
diskutil unmount /dev/disk4s2
or by volume location:
diskutil unmount "/Volumes/$NAME"
Mount a partition read-only if having trouble and trying to recover data:
diskutil mount readOnly /dev/disk4s2
Mount at a different location to the default /Volumes/<partition_metadata_name>
:
diskutil mount /dev/disk4s2 -mountPoint /path/to/dir
Mount / unmount partitions on a whole disk by reading its partition table:
diskutil mountDisk disk10
diskutil unmountDisk disk10
Verify a volume:
diskutil verifyVolume "/Volumes/$NAME"
Repair volume:
diskutil repairVolume "/Volumes/$NAME"
diskutil verifyPermissions "/Volumes/$NAME"
diskutil repairPermissions "/Volumes/$NAME"
Format a partition This is risky because there is no confirmation, better to do this from Disk Utility:
diskutil eraseDisk "$filesystem" "$name" "/dev/$diskN"
See which filesystems are available for formatting:
diskutil listFilesystems
Rename a disk:
diskutil rename "$volume_name" "$new_volume_name"
APFS requires GPT partition table
disk="disk4"
partition_table="GPT"
name="MyVolume"
filesystem="APFSX" # AppleFS case-sensitive, found from 'diskutil listFilesystems' above
size="0b" # integer + units suffix (b, m or g for bytes, megabytes or gigabytes) - '0b' uses all space
diskutil partitionDisk "/dev/$disk" "$partition_table" "$filesystem" "$name" "$size"
diskutil partitionDisk /dev/"$disk" "$partition_table" "$filesystem" "First" "$size" \
"$filesystem" "Second" "$size" \
"$filesystem" "Third" "$size" \
"$filesystem" "Fourth" "$size" \
"$filesystem" "Fifth" 0b # '0b' to use up all remaining space
Partition splitting doesn't seem to work with APFS, only macOS Extended, as APFS tells you to
diskutil apfs deleteContainer disk10
instead which leaves you with free space to create a new partition.
Either use Disk Utility above, a command like diskutil eraseDisk ...
or the more portable unix command dd
with a
custom command like this to do a moderate 3 pass overwrite
(tune number of passes
variable to suit your level of data recovery paranoia, eg. DoD standard 7 passes):
WARNING: disk numbers may shunt up in numbers as you insert more removal drives, especially for 'synthesized' virtual disks that display for volume containers
passes=3
time \
for number in $(seq $passes); do
echo pass $number
echo
time sudo dd if=/dev/urandom of=/dev/disk4 bs=1M
echo
done
Note: multiple passes are only for old inaccurate HDDs rotating mechanical metal platter disk. For SSDs, you only need a single pass.
List services:
sudo launchctl list
Load and start a service from a plist
file:
sudo launchctl load -F "/System/Library/LaunchDaemons/$name.plist"
sudo launchctl start "com.apple.$name"
Stop and unload a service:
sudo launchctl stop "com.apple.$name"
sudo launchctl unload "/System/Library/LaunchDaemons/$name.plist"
See dhcp.md for a practical example of using this for the built-in tftp server for PXE boot installing Debian off your Mac.
See the Binaries Debugging doc for commands to examine and work with binaries.
Macs and many computers don't come with CD/DVD anymore to save space, so you can either buy an external USB dvd-writer or create bootable USBs.
To create a bootable USBs from ISO image files intended for CD/DVDs in order to use them to install Linux or use a disk wiping distro like DBAN or ShredOS, you can download Etcher or use mac_iso_to_usb.sh from DevOps-Bash-tools:
mac_iso_to_usb.sh "$iso" # /dev/disk4
- UNetbootin app from github
- DiskUtility
- CLI
Set your filename in a variable so the following commands can be executed as is without editing:
export ISO="memtest86+-5.01.iso"
Convert it to make it bootable - will automatically add .dmg
suffix => .img.dmg
:
hdiutil convert -format UDRW -o "$ISO.img" "$ISO"
Figure out which is the USB disk - be careful or you'll destroy your system!
diskutil list
diskutil unmountDisk /dev/diskN
Tip: prefixing disk with 'r' uses raw disk which is faster:
sudo dd if="$ISO.img" of=/dev/rdiskN bs=1m # or 1M
diskutil eject /dev/diskN
Burn CD - insert blank CD then:
hdiutil burn "$ISO"
Ported from various private Knowledge Base pages 2010+