macOS tips

Extract .dmg (disk image)

Easiest way is to mount it in Finder or via open. For automation purposes, it can be also extracted or mounted directly in terminal.

Extract with 7zip (brew install p7zip):

7z x diskimage.dmg

Or it can be mounted via hdiutil:

hdiutil attach /path/to/diskimage.dmg
hdiutil info
hdiutil detach /dev/disk1s2

Create .dmg

Create a read-only image:

hdiutil create -srcfolder ./src -volname MyDmg -fs HFS+ -format UDRO my.dmg

See hdiutil create -help for other formats.

Existing image can be converted to another format:

hdiutil convert my.dmg -format ULFO -o compressed.dmg

Extract .pkg (installer package)

The .pkg archive can be extracted with xar:

pkgutil --expand installer.pkg installer_dir

Or at lower level (does not extract scripts):

xar -xf installer.pkg

The inner archives are gzipped cpio archives:

gzcat Payload | cpio -di

PC-style Home and End

I never got used to Home/End keys that only scroll to start/end of document. That is a feature I use very little, while in text boxes and on command line I need to jump to start/end of line a lot. So I always rebind the keys system-wide.

The standard combinations on macOS are these:

To remap the keys, create this file in user home:


Note that the KeyBindings directory may not exist yet.

Put this content in the file:

    "\UF729"  = moveToBeginningOfLine:; // home
    "\UF72B"  = moveToEndOfLine:; // end
    "$\UF729" = moveToBeginningOfLineAndModifySelection:; // shift-home
    "$\UF72B" = moveToEndOfLineAndModifySelection:; // shift-end

Other keys may be remapped in the same way. See all standard bindings:

plutil -p /System/Library/Frameworks/AppKit.framework/Resources/StandardKeyBinding.dict


Touch ID sudo

Add to beginning of /etc/pam.d/sudo:

auth       sufficient

External display: force RGB mode

When connecting external monitor via HDMI, macOS may choose “TV” mode (YPbPr/YCbCr) instead of native RGB mode. This may lead to awful artifacts - distorted colors or pixels. In my case, with monitor HP LP2475w, it looked as if the picture was downscaled and upscaled back again. Some pixels were in wrong place.

There is no user setting for display mode. It can be fixed only in Recovery, by adding a file to the protected system partition. Unfortunately, this may not survive OS upgrades.



List non-standard KEXTs

These have the strongest privileges, so it’s good to know about them:

kextstat --list | grep -vF ''

Debugger asks for admin password

Enable “developer mode”:

DevToolsSecurity -enable

After this, attaching a debugger doesn’t ask for admin password.