# Passive-aggressive advice on making macOS/macOS behave itself

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

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

Most of these commands are supposed to be run sudo root, and each may irremediably fuck up your computer, your life, and everything you have ever loved. Then it might challenge you to a break dance battle, I dunno. It won’t be my fault.

UPDATE: 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 general ones 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.

## Typing emoji

Cmd Ctrl Space.

## Tiling windows

Mission control provides some window-arrangement tricks, mostly side-by-side tiling of selected windows, which they term Split View.

Mission Control Keyboard shortcuts of note: ^ →, ^ ←, ^ ↑. The Split View itself has no shortcuts.

Or you can commit your time to learning a workflow based on someone’s passion-project window system, which might or might not be wise.

Tyler Hoffman reviews two contenders, Amethyst and chunkwm.

### Amethyst

Tiling window manager for macOS along the lines of xmonad.

Including various xmonad keyboard shortcuts, which is quicker if you like that thing.

### chunkwm

chunkwm is a tiling window manager for macOS that uses a plugin architecture, successor to kwm. It represents windows as the leaves of a binary tree, and supports binary space partitioned, monocle and floating desktops.…

chunkwm runs a local daemon to receive messages on a dedicated socket (port 3920).…

A third party program (e.g: skhd) is needed to map keyboard events to chunkwm actions.

But wait! There’s more!

### Spectacle

• Move to the left half — ⌥⌘←
• Move to the right half — ⌥⌘→
• Move to the top half — ⌥⌘↑
• Move to the bottom half — ⌥⌘↓

• Move to the upper left — ⌃⌘←
• Move to the lower left — ⌃⇧⌘←
• Move to the upper right — ⌃⌘→
• Move to the lower right — ⌃⇧⌘→

Windows may also be resized between thirds using any of the shortcuts above. For example, to have a window resized between 1/3 and 2/3 of the left region of the screen simply activate the left half ⌥⌘← keyboard shortcut more than once.

### Hammerspoon

Hammerspoon is fancy - it’s a window scripting interface sporting a whole Lua interpreter. Open source. It’s clearly much more than a window manager, and can do stuff like inspect USB eventts, click on menues, type for you etc. use with caution.

usage looks like this

hs.hotkey.bind({"cmd", "alt", "ctrl"}, "W", function()
end)

It has a cousin, phoenix which uses javascript as the language.

This reminds me… Hammertalk and Phoenix are contenders in another category:

## Actually usable scripting

Apple has shipped a slow, awful, incomprehensible scripting language forever. It’s called Applescript. After much time trying to persuade it to do things for me I feel comfortable asserting 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 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 is designed for UI testers not for UI users. You can do it with applescript of course, if your heart overunneth with bituminous hate.

## Concatenate PDFs

https://gotofritz.net/blog/howto/joining-pdf-files-in-os-x-from-the-command-line/#combining-pdf-files-on-the-command-line-in-osx

"/System/Library/Automator/Combine PDF Pages.action/Contents/Resources/join.py" \
-o PATH/TO/YOUR/MERGED/FILE.pdf \
/PATH/TO/ORIGINAL/1.pdf \
/PATH/TO/ANOTHER/2.pdf \
/PATH/TO/A/WHOLE/DIR/*.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)

pushd PATH/TO/PDFS
"/System/Library/Automator/Combine PDF Pages.action/Contents/Resources/join.py" \
-o PATH/TO/YOUR/MERGED/FILE.pdf \
(ls -rUt)

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

## Renew DHCP lease

My shitty router gets 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

## Which process is bound to $PORT? lsof -nP -i4TCP:$PORT | grep LISTEN # High Sierra or later
lsof -nP -iTCP:$PORT | grep LISTEN # earlier ## Which file is crashing/hanging that process? 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 in more ways. “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. ### 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: #!/bin/sh # # check for runaway distnoted, kill if necessary # PATH=/bin:/usr/bin 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 that this will break backup.

### 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

## 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:

open -ga iCal

## 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

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

## plist files are opaque binary messes

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

## Now my machine won’t boot properly heeeeeelp

I wouldn’t panic yet, probably the bootloadey whodangle thingy is broken again.

(Also applies if your CPU fan is going all the time, your machine is pausing lots, you are having trouble getting laid, or 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 a prayer.

### Other boot key combos of note

Alt
boot up off CD/USB Command-R
Recovery OS Shift
Safe mode Command-V
verbose mode Command-S
single user prompt

## DNS is all fucked up

sudo dscacheutil -flushcache
sudo killall -HUP mDNSResponder

## FFS iTunes never finishes syncing my phone it just 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. Heres 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

## My arbitrary server process is running out of file handles

ulimit -S -n 2048

## How do I stop my disk filling up with temporary backups?

sudo tmutil disablelocal

This shouldn’t be necessary, but I noticed that my spotlight indexing was stuck on the mobilebackups folder for some reason. Why was it even?

## 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.

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

sudo defaults write /System/Library/LaunchAgents/com.apple.gamed disabled -bool true

or:

launchctl unload -w /System/Library/LaunchAgents/com.apple.gamed.plist

in reference to this.

## Saving 300MB from skype on general principle

Update: the new version of Skype actually keeps this offal in the cache folder. (I imagine this is purely because of my passive-aggressive complaining. You’re welcome.) So now you don’t need to delete it. Unless you are deleting skype, which I did.

Since Skype is spookware I keep on my hard disk out of necessity, I am always mildly offended that it takes up 300MB of hard disk space for cached emoji for every single Skype username. (update: last time I checked they had managed to get it down to 200mb; still too much.)

This is all to store videos of Fozzie Bear and Christmas ornaments. The biggest Emoji-jockey on earth will never use 90% of this shit, and even though it claims to be a “cache”, it’s not in a cache folder, so it clogs up your backups with Fozzie Bear pictures. Put this in a launch agent:

rm -rf ~/Library/Application\ Support/Skype/*/media_messaging/*_cache_*

Don’t worry, Skype still works, and recreates the folder for you with the obsessiveness of a meth addict trying to polish your windshield; really you just need to remember that some Skype calls might be free in dollars, but they bill you 300mb of disk space/bandwidth for every call as well as the recordings of your cybersex, but you can get the 300MB disk space back afterwards, whereas the dick pics are lost to the US government forever. (It doesn’t seem to work if you trigger it from a folder action, so I set up a cron job to run that command every 10 minutes.)