Passive-aggressive advice on making macOS behave itself

Things I have to do to keep my laptop running so I can google how to fix other things

See also command lines it is tedious to remember for general Linux/unix/macOS/BSD commands.

⚠️ Most of these commands are supposed to be run sudo root, and each may irremediably ruin your computer, your life, and soil everything you have ever loved. Then it might challenge you to a break dance battle, I dunno. None of that will be my responsibility.

So many of these were filesystem-specific hacks that I broke out those into an article on filesystem-specific hacks. And others were about easing the pains of using macOS in the low-bandwidth majority world or macOS server.

The remaining tips are arranged so that the further you get down the list the longer it is since I have needed to know it; the later ones probably don’t work on modern macOS.

The motherships

Awesome MacOs Command Line lists how to fix a great many things from the keyboard.

A sampling:

# screenshot
screencapture -T 3 -t jpg -P delayedpic.jpg
# quicklook preview
qlmanage -p /path/to/file
#Convert Audio File to iPhone Ringtone
afconvert input.mp3 ringtone.m4r -f m4af

Typing emoji

As seen in typography. tl;dr Cmd Ctrl Space.

Concatenate PDFs

gotofritz says:

"/System/Library/Automator/Combine PDF Pages.action/Contents/Resources/" \
  /PATH/TO/ANOTHER/2.pdf \

If you are, e.g. concatenating chapters of a PDF book you downloaded from e.g. Springer, then you might have the creation dates in the correct order even if they are lexicographically correct. In that case you want (fish shell style)

"/System/Library/Automator/Combine PDF Pages.action/Contents/Resources/" \
  (ls -rUt)

There is some kind of problem with spaces in pathnames if you do it from a different folder.

Why do files open when I click on them too long?

I didn’t double click, honest guv.

That would be spring loading which one can turn off.

Preview modern image formats

WebP support is available by WebPQuicklook

brew install --cask WebPQuickLook

Like many modern casks you might need to assert trust for the developer

brew install --cask WebPQuickLook --no-quarantine

Setting HOMEBREW_CASK_OPTS coudl avoid some pain here.

qlImagesize offers even more features.

respond to dialog boxes without mouse

Disabled per default. There is a keyboard shortcut setting which enables tab-navigation.

Trusting homebrew casks

brew install --cask WebPQuickLook --no-quarantine

Setting HOMEBREW_CASK_OPTS could automatically approve some apps, although then you are casting aside a useful security feature.

Convert selected text

e.g. to upper case/lower case/HTML/markdown. There was this “services menu” technology which looked like it was going to do this for a while but that is no longer fashionable? 🤷‍♂ These days it seems one uses a third party app, Popclip.

Which file is crashing/hanging $PID?

Perpetual monitoring natively:

fs_usage $PID | grep /path/to/file

or the classic unix way:

lsof -r -p $PID | grep /path/to/file

See here for some tips on debugging runaway/hung/exploded processes. “See what syscalls does the process actually try to do and if there are any failed ones (status is not 0)” :

sudo dtruss -p PID

Case study: distnoted and lsd.

lsd runaway CPU

Some indexing jobs can cause it to choke, e.g. application bundles. Also, a corrupted database, which may be fixed thusly:

/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister \
  -kill -r -domain local -domain system -domain user ; killall Dock

distnoted runaway CPU

This is some kind of notifications daemon. I have no idea why it is out of control. It seems to be related to other processes such as certain version of flux or bartender. but the problem only seems to occur when my backup drive is plugged in. Hmmph. File a ticket?

Michael Rourke suggests doing this every minute:


# check for runaway distnoted, kill if necessary

export PATH

ps -reo '%cpu,uid,pid,command' |
    awk -v UID=$UID '
    /distnoted agent$/ && $1 > 100.0 && $2 == UID {
        system("kill -9 " $3)

But note this will break backup, so maybe just don’t.

Tiling windows

Usable scripting

Apple has shipped a slow, incomprehensible scripting language for as long as I have been aware of them. It’s called Applescript. After much time trying to persuade it to do things for me I feel comfortable asserting that using it will never save me time, although occasionally I execute a one-liner via osascript. There are some attempts to in-principle open up macOS’s cocoa to, e.g. javascript by jstalk or python via PyObjC but that’s a brutally low level to do things from unless you are an app developer, and the documentation is even worse. (and then why not just use Swift?)

However, people seemed to have converged on the UIKit accessibility API as a reasonable interface to script.

On this front, try Hammerspoon/Phoenix. pyatomac does the same for python but seems designed for UI testers not for UI users. You can do it with Applescript of course, if your heart overunneth with bituminous hate.

iTunes never finishes syncing my phone

It stays stuck on “importing photos”? Because you don’t use iCloud, right? For one thing, why would you voluntarily put your private photos in the hands of some notoriously secretive third party? For another, even if you wanted to, if you live in a bandwidth-poor country, iCloud sync is not just bad, it’s comedically bad. Atrociously, OS-floggingly slow and glitchy. “iClod”, let us call it. So you sync using a cable and iTunes, of course.

Except that, every couple of days, that breaks. Here’s how to fix it. (Note that this question refers to “iPhoto”, but the same bug has been faithfully carried over and reproduced in Aperture and Photos by diligent Apple devs, and the same fix works.)

Quit iTunes

rm -rf ~/Pictures/Photos\ Library.photoslibrary/iPod\ Photo\ Cache/

Note that this will reset iTunes to not sync your images, so you might need to reconstruct your settings.

Do that, try again.

Creating GUIs for shell scripts

Various options.

Automatically anonymized system stats



If you are reading this you are enough of a geek to need xcode

Run this:

xcode-select --install

Run out of file handles

Hmm, who knows how this works on the latest versions?

But the traditional advice is:

ulimit -S -n 2048

Wilson Mar says:


plist files are opaque binary messes

This is how to convert them to text. If you regard XML as text.

Bootloadey whodangle

For certain problems you need to reseat the SMC and PRAM which are formally referred to collective as the bootloadey whodangle. This seems to break often for me.

Symptoms include:

  • machine doesn’t boot
  • CPU fan going all the time
  • machine is pausing lots,
  • having trouble getting laid,
  • *a global geopolitical malaise is leading to the ineluctable slide of civilisation into ecosocial catastrophe.

Do these things:

  • Reset the SMC: Switch the computer off, then, while off, on the built-in keyboard, press the (left side) Shift-Control-Option keys and the power button at the same time.
  • Reset the PRAM: Switch the computer off, then, while booting, press and hold the Option-Command-P-R keys until the startup sound chimes again.
  • Build a small pyramid over your laptop from bronze and crystals. Burn some incense and your Applecare guarantee in a brazier atop it. Surround it with small pictures of your departed ancestors. Make an offering of fruit and prayer.

Other boot key combos of note

offer a boot menu
boot up off CD/USB
Recovery OS
Safe mode
verbose mode
single user prompt

Networking from the command line

See also network hacks from som enon-mac-specific ones.

Renew DHCP lease

My previous awful router would cross if I leave the house and when I come back I try to use the same DHCP lease. But it’s a one-liner to fix.

sudo ipconfig set en0 DHCP
ipconfig getpacket en0

Notarization slowdowns

odgard notes that some things are slows in Macos 10.15+. Fixes suggested include

sudo spctl developer-mode enable-terminal
sudo spctl --master-disable

See also Jeff Johnsons analysis.

Turning it off and on again

networksetup -setairportpower en0 off

Turn on wifi on your macbook from the Mac macOS terminal command line:

networksetup -setairportpower en0 on

List available wifi networks from the Mac macOS terminal command line:

/System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport scan

Join a wifi network from the Mac macOS terminal command line:

networksetup -setairportnetwork en0 WIFI_SSID WIFI_PASSWORD

Find your network interface name:

networksetup -listallhardwareports

DNS is choked up

Oh no! did you use your computer in some wacky workplace network that DNS blocks “frivolous” websites? You need to flush it.

DNS flush command keeps changing, eh?:

sudo dscacheutil -flushcache
sudo killall -HUP mDNSResponder

More generally, avoid the problem with upgraded DNS.

Focus stealing

Stop stealing focus from me, slow app, I clicked on you like 30 seconds ago.

CNET says: How to keep applications from stealing focus. But their first idea (edit application, break code signature) is not a viable idea in the modern world.

The command-line background-open still works, although if I wanted to launch apps this way I would be using Linux.

open -ga iCal

The Apple supported solution is for you to buy a faster computer.

Installing skype

Never install skype! Skype is spookware. If you must use it, use the web version.

Stop gamed and other processes leaking your data and wasting precious network sockets for no reason

binary bob says :

sudo defaults write /System/Library/LaunchAgents/ disabled -bool true


launchctl unload -w /System/Library/LaunchAgents/

in reference to this.

macOS claims it forgot my email/contacts/calendar password again

Then an hour later it forgets again again?

Woe! I fixed this once then I forgot how I did it.

Linkdump while I sort it out again again again:

Continuous [sic] request for the CalDAV password? Here’s one solution:

  1. Go to the  Apple menu and choose System Preferences
  2. Choose the ‘iCloud’ preference pane
  3. Sign in to iCloud at the OS X preference panel — note if you’re already signed in here but still seeing the pop-up message, you can sign out then sign back in to stop that password prompt from happening again
  4. Close System Preferences

Using Chromium (“open-source chrome”)

Harder than it should be; Google really wants you to use their furtively modified alternate branch, Google Chrome.

Anyway, here is a supplier of unsullied Chromium.

Reset semaphores

I can’t even remember why I needed to do this, or how I worked it out, but geez it saved my bacon from something or other.

ipcs -s | grep " 0x" | awk '{ print $2; }' | xargs -n 1 ipcrm -s

Time machine

precision control

tmutil is the command-line app which allows you to do proper monitoring and control of the time machine service. It includes, for example, backup statistics

There is also Time Machine editor which controlsvarious time machine settings including local snapshot, below. If you are using a oldish machine without a fast drive then this is useful.

local snapshots, mess

I think this is largely a cosmetic issue, but macOS keeps a local copy of various versions of your files around, called local snapshots or mobile backsups depending where you look.

If, like me, you version everything in git, this is mostly annoying, but also I think harmless as they are self-cleaning. Nonetheless stuff did go wrong for me. I noticed that my spotlight indexing was stuck on the mobilebackups folder for some reason. Why was it even?

What Crap Is This: OSX’s Mobilebackups:

sudo tmutil disablelocal

Re-time stupid alarms

By default, if you use notifications from Apple Calendar, the notification for events is at 9am, right in the middle of the first meeting of the day. So you are half way through the report-back presentation about your recent conference visit, your laptop pops up RECTAL EXAMINATION TODAY.

You aren’t supposed to be able to change this because the thought of this cruelty is all that gets jaded Apple executives out of bed in the morning, but there is a hack they forgot to stop.