zs3.me

Useful MacOS Command-Line Tips

Revision 12
© 2020-2026 by Zack Smith. All rights reserved.

A lot of what I recommend in my Linux command-line tips page also applies to MacOS.

This page provide some addition MacOS-specific command-line tricks.

Devices

List devices

MacOS doesn't have the usual lsusb and lspci commands, so we have to add equivalents.

  • alias lsusb="system_profiler SPUSBDataType"
  • alias lspci="ioreg -P IPCI -l -w 0"

Print the CPU type

  • sysctl machdep.cpu.brand_string

Print the number of CPU cores

  • sysctl machdep.cpu.cores_per_package

Print the memory page size

  • sysctl hw.pagesize

Print the model info

  • sysctl hw.model

Power

Live display of CPU cores' speeds and power usages

  • sudo powermetrics

Audio

Play an audio file

  • afplay file.mp3

Make a ringtone file

  • afconvert -f m4af -d aac myfile -o myfile.m4a

Images

Convert an image to a different size

 function resize_image {
  # Parameter 1: input file
  # Parameter 2: output file
  # Parameter 3: new size
  cp $1 $2
  sips --setProperty format png -Z $3 $2
 }

Display

Apple's computers are known to cause eye strain. But it's not just caused by their laptops' and iMacs' screen. Even a Mac Mini, connected to a good monitor, can cause eye strain.

There are at least 5 ways in which this happens.

  1. PWM i.e. pulse width modulation, which uses flickering to simulate different brightness levels.
  2. Temporal dithering, which uses rapid switching between colors to simulate a large color gamut then the display will natively support.
  3. FRC, which is similar to temporal dithering but uses a whole-screen approach.
  4. Blue light, which is known to be unhealthy for your eyes' retinas.
  5. Bad panels. Apple uses multiple factories to make their screens and some produces eye-straining products.

PWM is mainly a feature of Macbook Pros. The current Macbook Airs are shown using the Opple Lightmaster 4 to have slight PWM that dips into the harmful zone.

https://i.imgur.com/j2oOBG5.png

Temporal dithering is used by all Macs. It can be disabled with software.

Commands related to panels

 ioreg -lw0 | grep -i panel-serial-number
 ioreg -lw0 | grep -i raw-panel-serial-number
 ioreg -lw0 | grep -i enableDither
 ioreg -lw0 | grep IODisplayEDID
 ioreg -lrbit -d0 -w0 -r -c AppleCLCD2 -a
 system_profiler SPDisplaysDataType
 /usr/libexec/corebrightnessdiag nightshift-internal
 /usr/libexec/corebrightnessdiag status-info
 '/System/Library/ColorSync/Calibrators/Display Calibrator.app'
 defaults -currentHost write -g NSCGSWindowSkylightSupportsMoreScaleFactors -bool yes
 defaults -currentHost write -g NSWindowScaleFactor -int 1
 ioio -s AppleARMPWMDevice enabled false

Commands to assess the situation

Fonts

If you're using a non-Retina display and the fonts look blurry, you can turn off MacOS's blurry font anti-aliasing like so:

  • defaults write com.apple.Terminal AppleFontSmoothing -int 0

Files

 fs_usage

Network

Wifi sniff mode

  • sudo airport en0 sniff 1

Do an sftp with PEM file

  • sftp -i myfile.pem user@host

Change Wifi MAC address

There's a chance this may only work on Intel Macs with Intel Wifi cards.

  function MAC {
    sudo /etc/rc.d/rc.networkmanager stop
    sudo /sbin/ifconfig wlan0 down
    sudo /sbin/ifconfig wlan0 hw ether 10:20:30:40:50:60
    sudo /etc/rc.d/rc.networkmanager start
    sudo /sbin/ifconfig wlan0 | grep ether
  }

WiFi rate limit

This works in MacOS 10.9 and earlier:

  • sudo ipfw pipe 1 config bw 1KByte/s

Privacy

Disable iCloud

iCloud is now harder to disable than in the past.

  1. Go into Settings, click on your account, and specifically disable it. Some parts of it will still be enabled.
  2. You will then only need to log in with your Apple ID to install software.

The Privacy, Security and OSINT podcast has a magazine and its 5th issue covers Ventura privacy:

Deselect file types that Spotlight scans

  1. Go into Settings and on the left side, select Spotlight/Siri.
  2. Uncheck the file types that you don't want scanned e.g. all of them.

Disable Spotlight indexing

Method 1

 sudo mdutil -i off -a

Method 2

 sudo launchctl unload -w \
  /System/Library/LaunchDaemons/com.apple.metadata.mds.plist

Delete Spotlight plugins

A definite privacy risk involves Spotlight plugins, which may be installed without your knowing or being informed when you install commercial software or freeware. Always look in the following directories for these as they may be spyware:

  • ~/Library/Spotlight/
  • /Library/Spotlight/
  • /System/Library/Spotlight/

Software

Install Rosetta

 softwareupdate --install-rosetta --agree-to-license

Enable side-loading of apps

 sudo spctl --master-disable

Install command-line utilities

Just type git or gcc in Terminal and hit Enter and you'll be prompted.

iOS Simulator

These will require that you have Xcode installed.

Launch the Simulator app

 open /Applications/Xcode.app/Contents/\
  Developer/Applications/Simulator.app

List iOS devices

  • xcrun simctl list devices -j

List simulators

  • xcrun simctl list

Erase all simulators

  • xcrun simctl erase all

Insert a photo into the running simulator

  • xcrun simctl addmedia booted myfile.png

Take a screenshot

  • xcrun simctl io booted screenshot image.png

Record the simulator's screen

  • xcrun simctl io booted recordVideo movie.mov

Cause the simulator to open a URL

  • xcrun simctl openurl booted 'myappscheme:dothis'

Install your app

  • xcrun simctl install booted MyApp.app

The full path to your .app should be used, which will be in DerivedData.

Uninstall your app

  • xcrun simctl uninstall booted MyApp

Launch your app

  • xcrun simctl launch booted MyApp

Kill your app

  • xcrun simctl terminate booted appname

  • xcrun simctl launch booted appname

Stream your app's logs

  • xcrun simctl spawn booted log stream - level=debug

Dump the defaults for your app

  • xcrun simctl spawn booted defaults read com.company.app

Set a default value for your app

 xcrun simctl spawn booted defaults \
  write com.company.app \
  key -string value

Delete unavailable simulators

  • xcrun simctl delete unavailable

Firewalls

It's a good idea to install an outgoing firewall to prevents apps or even Apple from stealing your data.

Two popular ones are:

Related links

1072575825