Skip to content
Dave Cox edited this page Dec 4, 2025 · 15 revisions

To view hidden files in Finder:

in newer macOS, just hit Cmd + Shift + .

alternately, and for older macOS:

> defaults write com.apple.Finder AppleShowAllFiles true
> killall Finder

Show all filename extensions:

Finder > Preferences > Advanced

Navigate Finder to a Unix Path

To check the swap file, launch Finder and press Command + Shift + G to open the Go To field, then copy and paste the following path:

/private/var/vm/

Take Screenshot

post-Mojave: + Shift + 5 brings up a GUI

+ Shift + 3 snaps the entire screen (all displays)

+ Shift + 4 lets you select area to snap

  • + Shift + 4, Space: lets you select a window to snap

+ Ctrl + Shift + 4 lets you select area to snap; sends to clipboard rather than file

  • ? so maybe + Ctrl + Shift + 4, Space: lets you select a window to snap, then sends to clipboard

Change Where Screenshots Are Saved

+ Shift + 5 GUI as above > Options > Other Location…

TODO: image-20240329-160950.png

Lock Screen

Ctrl + + Q

Put Machine to Sleep from Command-Line

sudo shutdown -s now

Shortly:

sleep 1; sudo shutdown -s now

Sublime Merge customization

  • /Users/dcox/Library/Application Support/Sublime Merge/Packages/User/Tag.sublime-menu
  • /Users/dcox/Library/Application Support/Sublime Merge/Packages/User/Default.sublime-keymap

reference:

  • /Users/dcox/tmp/Default.sublime-package/Main.sublime-menu
  • /Users/dcox/tmp/Default - Merge.sublime-package/Default (OSX).sublime-keymap
  • /Users/dcox/tmp/Default - Merge.sublime-package/Default (Windows).sublime-keymap

sudo without password

  • pushd /private/etc/sudoers.d
  • sudo visudo -f ./test-no-pass
  • enter: test ALL = (ALL) NOPASSWD: ALL
    • where test is the account to have no-password sudo privilege.
  • look for validation error messages from visudo

LaunchDaemons / LaunchAgents

These are controlled and configured with the command-line launchctl utility. When dealing with LaunchDaemons, use sudo; when dealing with LaunchAgents, don’t.

[sudo] launchctl load|unload… is legacy/obsolete syntax (though these still work as of macOS Tahoe). Instead use:

for LaunchDaemons:

sudo launchctl bootstrap system /Library/LaunchDaemons/com.bgrove.activtrak.daemon.plist
sudo launchctl bootout system /Library/LaunchDaemons/com.bgrove.activtrak.daemon.plist

for LaunchAgents:

launchctl bootstrap gui/<uid> /Library/LaunchAgents/com.bgrove.activtrak.agent.plist
launchctl bootout gui/<uid> /Library/LaunchAgents/com.bgrove.activtrak.agent.plist

Disabled Status

Launchd daemons/agents may be disabled such that the processes do not start even though everything else about the installation of the daemon/agent and its plist file are in order.

To see which are disabled (these list enabled too):

launchctl print-disabled system
launchctl print-disabled gui/<uid>

To enable:

launchctl enable gui/<uid>/com.bgrove.scthostp
sudo launchctl enable system/com.bgrove.svctcom

Mission Control

(launch) Mission Control: ctrl + ↑
Application windows: ctrl + ↓
Show desktop: F11
Move left a space: ctrl + ←
Move right a space: ctrl + →
Switch to Desktop n: ctrl + n

Use Mac Laptop with Lid Closed

  • Connect external monitor, keyboard, mouse & power, and test them
  • System Preferences > Energy Saver > Power Adapter
  • Set Turn display off after to Never

Alternately, try one of these 3rd-party apps: Caffeinated, Amphetamine, Insomniac

Use Mac Laptop with External Display(s), Lid Open, Built-in Display Off

Lid open dissipates heat better?

TBD…

Change computer name

System Preferences > Sharing > Computer Name (edit box) Optionally click the Edit button to change the local-network name.

Creating root-level directories and symbolic links on macOS Catalina+

(which has read-only root)

Create/edit /etc/synthetic.conf with permissions (root:read+write, wheel:read, everyone:read)

https://derflounder.wordpress.com/2020/01/18/creating-root-level-directories-and-symbolic-links-on-macos-catalina/

For example, /etc/synthetic.conf may look like this:

# create an empty directory named "foo" at / which may be mounted over
foo

# create a symbolic link named "bar" at / which points to
# "System/Volumes/Data/bar", a writeable location at the root of the data volume
bar     System/Volumes/Data/bar

# create a symbolic link named "baz" at / which points to "Users/me/baz"
baz     Users/me/baz

Note: apps are often not fooled by such symlinks; they’ll resolve to the true path. So if you link /repos/System/Volumes/Data/repos, then apps will end up remembering and displaying /System/Volumes/Data/repos/.... To avoid that, use mountpoint folders rather than symlinks in the root. But mountpoints require you have a volume to mount. Fortunately APFS Containers allow you to create more volumes (in Disk Utility.app) that share the container capacity with /System/Volumes/Data. Also use Disk Utility to unmount them from their default location, and get their UUIDs. Then use /etc/fstab to auto-mount them at the desired location each boot:

UUID=F66CDCD0-EB45-4562-A6BD-D1C7C73C3AA1 /repos apfs rw,nobrowse 0 2
UUID=9F56D36B-D2D0-456C-B555-20FBF10861BD /tools apfs rw,nobrowse 0 2

(Use sudo vifs to edit /etc/fstab safely.)

Xcode

Install Command-line Tools

sudo xcode-select --switch /Applications/Xcode_version.app
sudo xcode-select --install

Fix Slow File Transfer Over LAN

http://www.debugginlife.com/solved-very-slow-file-transfer-on-mac-shares-smbafp/

temporary: sudo sysctl -w net.inet.tcp.delayed_ack=0 (where default is 3)

permanent: sudo vim /etc/sysctl.conf, therein net.inet.tcp.delayed_ack=0, reboot

Key Bindings

~/Library/KeyBindings/DefaultKeyBinding.dict

https://ss64.com/osx/syntax-keybindings.html

https://web.archive.org/web/20160314030051/http://osxnotes.net/keybindings.html

https://www.hcs.harvard.edu/~jrus/Site/Cocoa Text System.html

Extract Files from Installer Package (.pkg file)

pkgutil --expand-full <pkg-file> <destination-dir>
(destination-dir need not exist)
example:
pkgutil --expand-full AppInstaller.pkg ./extracted

Crash On-Demand

To make a process crash, from outside the process, simulate a segmentation-violation:
sudo kill -SEGV <pid>

Debugger Stops on Signal

And thus prevents debugging signal handling, such as process shutdown on SIGTERM.

You can configure the debugger not to stop, and let the signal pass to the process’s signal hander. Issue process handle -p true -s false SIGTERM at the lldb console prompt, which is available in the Xcode Debugger Output pane when the process is paused.

_sigtramp()

_sigtramp() is a trampoline that receives any signal (requiring user-mode handling), and then is responsible for finding and invoking the actual handler function.
https://github.com/apple/darwin-libplatform/blob/main/src/setjmp/generic/sigtramp.c

Xcode Exit Status 65

(CI reports “Exited with code exit status 65” or build script fails with exit status 65)

This occurs if a build step executed by xcode-build fails, but it is not necessarily the last step or a CodeSign step. Search back through the build log for <step> failed with a nonzero exit code.

Sometimes this occurs when a unit test crashes:

02:21:56.860554 [ RUN      ] XyzTests.RequestCalledOnDemand
02:21:56.860561 /.../XyzTests.cpp:228: Failure
02:21:56.860568 Expected equality of these values:
02:21:56.860575   std::future_status::ready
02:21:56.860581     Which is: 4-byte object <00-00 00-00>
02:21:56.860588   foo2.events.wait_for(3s)
02:21:56.860595     Which is: 4-byte object <01-00 00-00>
02:36:32.638178 terminateWithCrashDump(): crash dump not implemented for macOS; just terminating.
02:36:32.641171 Command PhaseScriptExecution failed with a nonzero exit code

Dbg Tracing to OS

use os_log_debug(log, message), where log is from os_log_create(subsystem, category).

So we want to view the Mac’s unified logging for level debug, subsystem 'as.passed.to.os_log_create'.

sudo log config                                                         \
        --subsystem "as.passed.to.os_log_create"                        \
        --mode "level:debug,persist:debug"

It may be necessary to create the subsystem in the logging config first:

sudo defaults write                                                            \
    /Library/Preferences/Logging/Subsystems/as.passed.to.os_log_create.plist   \
    DEFAULT-OPTIONS                                                            \
    '{Level={Enable=debug;Persist=debug;};"Event-Log"={Enabled=1;};}'
sudo log show --debug --process scthost [...] --last 30m
sudo log show --debug --predicate 'subsystem=="as.passed.to.os_log_create"' --last 30m
sudo log stream --debug --predicate 'subsystem=="as.passed.to.os_log_create"' --process my_process_name

Symbols in Object Code

You can use objdump (previously otool) to see the symbols defined, and those referenced, in an object file.

objdump --syms --demangle ./MyCpp.o

I think those referenced but not defined in the same object file are "undefined" and designated with *UND* in the output. Presumably these are typically resolved from other object files or libraries at link time. And if they cannot be found, then the linker issues undefined-symbol errors.

Prevent machine wake due to Power Nap

(which lights up external monitors if connected)
https://support.apple.com/en-ae/guide/mac-help/mh40774/mac
https://discussions.apple.com/thread/252061187?page=2&sortBy=rank

sudo pmset -a powernap 0

Reset Location Services permission of an app to unprompted state

  • Determine the application's bundle ID
  • Uninstall the application
  • Grant the Terminal app "Full Disk Access" under System Settings > Privacy & Security
  • Edit the Location Services permissions database, using shell commands in the Terminal app:
sudo /bin/zsh
cd /var/db/locationd
chmod 664 clients.plist
chown root clients.plist
plutil -convert xml1 clients.plist
vi clients.plist
  • Delete the dictionary entry for your app (which is an entire sub <dict>...</dict>), e.g. with key <GUID>:i<bundle ID>:
  • Save and quit the text editor (vi: :wq)
  • kill -KILL <pid-of-locationd>
  • Notice that the ownership of clients.plist is reverted to _locationd, and locationd resumes running immediately.

Note, I was unable to get plutil or PlistBuddy to remove entries from clients.plist, with each claiming the <GUID>:i<bundle ID>: entry was not present, hence the conversion to XML and subsequent use of vi.

Accelerate Sequoia monthly prompt for Screen Recording permission

Note this pertains to apps using a single-screenshot API rather than those using ScreenCaptureKit streaming with the associated sharing picker GUI.

Edit ~/Library/Group Containers/group.com.apple.replayd/ScreenCaptureApprovals.plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>/Library/PrivilegedHelperTools/scthostp</key>
	<date>2024-09-26T16:40:12Z</date>
</dict>
</plist>

Remove the ... and following ... associated with the app for which you’d like to see the prompt sooner:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
</dict>
</plist>

Kill the replayd agent, so it’ll restart and reload the above .plist file:

> ps -A | grep replayd
 6506 ??         0:03.11 /usr/libexec/replayd
 6508 ttys000    0:00.00 grep replayd
> kill -KILL 6506

The “monthly” Screen Recording permission prompt should appear the next time the app tries to take a screenshot.

TCC Database(s)

TCC = Transparency Consent and Control

macOS:

/Library/Application Support/com.apple.TCC/TCC.db
/Library/Application Support/com.apple.TCC/MDMOverrides.plist (binary plist format)

/Users/username/Library/Application Support/com.apple.TCC/TCC.db

Non-TCC:

Location Services: /var/db/locationd/clients.plist

iOS:

/private/var/mobile/Library/TCC/TCC.db

Viewing

The .db files are SQLite (3) format. They’re protected, so we won’t be able to change them using sqlite3 tools.

cp "/Library/Application Support/com.apple.TCC/TCC.db" /Users/user/issues/TCC/TCC.db
chown <user> /Users/user/issues/TCC/TCC.db
sqlite3 /Users/<user>/issues/TCC/TCC.db
sqlite> .schema
...
sqlite> .tables
access            
active_policy     
expired         
access_overrides  
admin             
policies
sqlite> select * from access;
...
sqlite> select service, client_type, client, auth_value, auth_reason from access where service = "kTCCServiceScreenCapture";
...
kTCCServiceScreenCapture|1|/Library/PrivilegedHelperTools/scthostp|2|4
           ~~~~~~~~~~~~~                                  ~~~~~~~~
...

Clone this wiki locally