Mac-notes

Mac usage notes

This is https://github.com/Ben-Voris/Mac-notes.git.

A prettier version is at https://ben-voris.github.io/Mac-notes/.

Function keys

How to use the function keys on your Mac either:

Keyboard shortcuts

Cut, copy, paste, and other common shortcuts

Much of this is from Mac keyboard shortcuts

More text editing keys

Moving on the line and up an down lines

These key chords behave different in different apps.

In VS Code, they move both the display and where text is inserted. In some documents, they seem to move based on document structure. For example, in this Markdown document, Control + down-arrow can move to the last section and, in that case, pressing these keys a second time move to the bottom of the document.

In Notes, they move what text is displayed but do not move where text is inserted.

Create a line break in apps where Return means Send

MacBook Trackpad setup

Settings > Trackpad

Remember to use both hands. For example, for me, swiping from the left is easier with the left hand. When selecting a large amount of text, it is possible to start the “click drag” with one hand and extend it with the other.

Point & Click

Force click is a longish hard press that, if haptic feedback is enabled, gives a distinct “bump” as feedback.

An example of a “data detector” is a dictionary lookup that can appear when a word is selected that is in the dictionary. See dictionary lookup.

Scroll & Zoom

Enable

More Gestures

Mouse command when editing text

Mouse command when reading text

Dictionary lookup

Dictionary lookup can be enabled by turning System Settings > Trackpad.

Sometimes this does not work, even for words that are in the dictionary. And then it starts working.

Unfortunately, the mouse command is not consistent. All start with clicking on a on a word to select it, then a “Force Click” but with a different number of fingers.

Apple Mail app

Messages app

Safari

VS Code

Keyboard shortcuts for macOS

VS Code steals the default minimize Command + M. I found no shortcut that uses only this, but some use it in conjunction with other keys, like Command + K + M for “Change Language Mode” and Shift + Command + M for “Toggle Problems”.

Opening a file in VS Code from shell

At the VS Code command prompt, type shell and select Install 'code' command in PATH, then follow its prompt. You can then enter commands like these:

code ./
code file-name

Contrary to what it says, on MacOS, this command dos not update PATH but creates this:

/usr/local/bin/code: symbolic link to /Applications/Visual Studio Code.app/Contents/Resources/app/bin/code

Or use the open(1) command, as in this example:

open --new -a "Visual Studio Code" --args --new-window file-name

It is necessary to tell open(1) to open a new window (--new) and to tell VS Code to create a new window with --new-window.

Open a directory with VS Code from Finder

Use Automator to create a Quick Action for Files and Folders.

Open a Folder in VS Code through Finder in MacOS

  1. Start Automator
  2. Click on Quick Action, Click on Choose
  3. Set Workflow receives current to Files or Folders in Finder
  4. Click on Image and Choose. This opens a Finder-type window
  5. Click on Application
  6. Click on Visual Studio Code, click on Choose Note that Image is now Custom
  7. Find Open Finder items in the Library
  8. Clock on Open With, then find Visual Studio Code
  9. Click on File > Save (or Command + S) and enter something like “Open with Visual Studio Code”.

To use what you just created:

  1. Control + Click on the item
  2. Click on Quick Actions
  3. Click on the name you gave to the action.

OCR

This depends upon displaying the photo in the Preview app and so does not work for a photo that is in a shared album.

Interact with text in a photo using Live Text in Preview on Mac

From email

Double click on the picture to open the Preview app.

From Photos

Once in Previews

Photo App

Keyboard shortcuts and gestures in Photos on Mac

This only works for a local photo and does not work for a photo in a shared album.

What to install

Some iOS apps, like Feedly, Netflix, Youtube, etc. are not available for Mac. For these, visit the page, click on the Share (up arrow) and click on Add to Dock. Links that are added to the dock also appear in the Apps folder.

To install VS Code

https://code.visualstudio.com/download

Add these extensions

   
Bash IDE mads-hartmann.bash-ide-vscode
Bookmarks alefragnani.Bookmarks
C/C++ ms-vscode.cpptools
C/C++ Themes ms-vscode.cpptools-themes
markdownlint DavidAnson.vscode-markdownlint
Rewrap Revived dnut.rewrap-revived
Sort JSON objects richie5um2.vscode-sort-json
Sort lines Tyriar.sort-lines
Spell Right ban.spellright

Sign into GitHub.

To install exiftool

exiftool

macOS will display “Apple could not verify …. is free of malware …” and will offer to “Move to Trash”. Click Done and follow the steps in Removing a file from quarantine.

To install SQLLite browser

Download at https://download.sqlitebrowser.org

See https://github.com/sqlitebrowser/sqlitebrowser/.

To install Tor Browser

https://www.torproject.org/download/

To install Signal

https://signal.org/download/macos/

Existing chats from other devices are not synchronized.

To install Firefox

https://www.mozilla.org/en-US/firefox/mac/

To install DigiKam

A photo cataloging tool I used on Linux

https://www.digikam.org/download/

Installing this requires removing the installer from quarantine.

GPSBabel

A GPS format converter.

https://github.com/gpsbabel/gpsbabel

Installing this requires removing the installer from quarantine.

OpenJDK (Java)

Download the tar from https://jdk.java.net/23/

Install in /usr/local with

sudo tar -xf ~/Downloads/toInstall/openjdk-23.0.2_macos-aarch64_bin.tar.gz -C /usr/local/bin/

Or put it in your home directory with

tar -xf ~/Downloads/toInstall/openjdk-23.0.2_macos-aarch64_bin.tar.gz -C ~/

Then add this to your .bashrc or similar:

export JAVA_HOME=/usr/local/bin/jdk-23.0.2.jdk/Contents/Home/
PATH="${PATH}:${JAVA_HOME}/bin:"

Garmin programs

Installed but not sure if they’re useful

Install osxphotos

Requires Macports.

osxphotos gives information about files stored in the photo database.

sudo port install osxphotos

From Mac App store

Terminal app

Apple wants me to use zsh because it hooks into Apple thingies.

To avoid the annoying warning about zsh when starting bash, put this into ~/.zshenv:

# See https://support.apple.com/en-us/102360
export BASH_SILENCE_DEPRECATION_WARNING=1

Sometimes Control + C stops working and you’ll hear a beep. When this happens, try Command + .

When you exit the shell, Terminal will stay running. To prevent this, in the Terminal settings Profiles, change “When the shell exits” to “Close if shell exited cleanly”.

Terminal Keyboard shortcuts

Keyboard shortcuts in Terminal on Mac

Do not confuse Command with Control. For example, Command + D splits the terminal window into two panes but Control + D is an end-of-file.

The keyboard shortcuts cannot be disabled. They can be assigned to a different chord.

(Shift + Command + D undoes the split created by Command + D.)

Copying file names from Finder to Terminal

First, select a file or files in Finder, then drag the files to a Terminal window using Command + Click, much like moving files in Finder.

Accessing the Photo Library

Try pointing SQL Lite browser at database/Photos.sqlite.

The picture files are in "${HOME}/Pictures/Photos Library.photoslibrary/" The double quotes are necessary (that, or escape the space).

For one picture, with some edits, there are six files. See exiftool output for an example jpeg.

scopes/cloudsharing/data contains at least some (all?) of the photos from shared albums.

This command launches the Preview app from the zsh (not bash) command line:

open -a Preview -- "${HOME}/Pictures/Photos Library.photoslibrary/originals/0/0FB91698-EF23-48BF-96A9-F7902A77E118.jpeg

See osphotos

If you have the full path to the photo, the terminal open command will open the preview app.

Things to check out for Photos

iCloud Photo downloader

To copy from iPhone to Mac or NAS PhotoSync – transfer photos on App store Visit photosync-app.com for a complete feature list.

Photo Exifer app

Photo Exifer claims to import XMP data to the Photos app. See How to import XMP sidecars to Photos on Mac?

Photo Exifer is compatible with extensible metadata files, supporting XMP files from Apple Photos and JSON files from Google Photos. It allows you to read photo metadata from XMP and JSON files and write it back to the corresponding photos

Photo Exifer likely cannot write files to a RAW file. It does not create an XMP file.

mlds(1)

mdls lists the metadata attributes for the specified file

It will display GPS info, etc. from a photo that has data.

Note that GPS data added to a photo using the Photos app is not written to the file.

Controlling the dock

These use defaults(1) to “access the Mac OS X user defaults system”.

Prevent rearranging the dock

When using the trackpad, and the default configuration, I find it too easy to accidentally rearrange the dock. Here’s a command to prevent that.

defaults write com.apple.Dock contents-immutable -bool true && killall Dock

When this contents-immutable is set, apps cannot be drug into the dock.

Allow rearranging the dock

defaults write com.apple.Dock contents-immutable -bool false && killall Dock

defaults can also be used to control whether one can change the docks’s position com.apple.Dock position-immutable and size com.apple.Dock size-immutable.

Example of using defaults to read a value

defaults read com.apple.Dock contents-immutable

Homebrew vs. MacPorts

Homebrew and MacPorts are ways of getting open source tools running on a Mac. Both are actively maintained.

Here are Apple’s ports

MacPorts and their mpstats tool installed quickly but the first real package I installed, shellcheck, took tens of minutes because it pulled so many dependencies - 465 packages per port echo rdepof:shellcheck - some of which did not have prebuilt binaries.

Thoughts on macOS Package Managers is in favor of MacPorts because it is more consistent with Linux and issues with how the project is run. Notes that Homebrew is sometimes updated more quickly. Though this is old, more recent pages link to it.

Responses to this Reddit lean towards Homebrew because it usually carries over with less between MacOS releases, though some note that can cause more problems than it fixes because Homebrew depends on the MacOS libraries. Also notes that its refusal to share /usr/local can cause problems.

MacPorts

Homebrew

List USB devices

system_profiler SPUSBDataType

Example output with Garmin e-collar attached:

USB:

    USB 3.1 Bus:

      Host Controller Driver: AppleT8132USBXHCI

        Vendor-Specific Device:

          Product ID: 0x0003
          Vendor ID: 0x091e  (Garmin International)
          Version: 0.01
          Speed: Up to 12 Mb/s
          Location ID: 0x03100000 / 1
          Current Available (mA): 500
          Current Required (mA): 500
          Extra Operating Current (mA): 0

    USB 3.1 Bus:

      Host Controller Driver: AppleT8132USBXHCI

    USB 3.1 Bus:

      Host Controller Driver: AppleT8132USBXHCI

ioreg -p IOUSB lists information about the USB controllers but I can’t get it to display the attached device, as shown above.

Recording the screen / Screen capture a problem

How to record the screen on your Mac

Use the Screenshot app

  1. Open the Screenshot app by pressing these three keys together: Shift + Command + 5.
  2. You should see an onscreen toolbar with three controls for capturing a still image of your screen, followed by these two controls for recording a video of the screen:
    • Record Entire Screen
    • Record Selected Portion. You can adjust the selected portion by dragging its borders with your mouse or trackpad.
  3. Before starting your recording, you can click Options in the toolbar to change the recording settings:
    • To record your voice or other audio with the screen recording, choose a microphone.
    • To show a black circle around your pointer when you click, choose Show Mouse Clicks.
    • To set a recording timer, choose the number of seconds to wait before recording begins after you click Record.
    • To change where the recording will be saved after you stop recording, choose a different “Save to” location. By default, recordings are saved to your desktop.
  4. To start recording, click the Record button in the Screenshot toolbar.
  5. To stop recording, click the Stop button in the menu bar, or press Command + Control + esc (Escape).
  6. When you see a thumbnail of the recording in the corner of your screen, click it to edit the recording. Or wait for the recording to save to your desktop.

Learn more about using the Screenshot app

Use QuickTime Player

  1. Open QuickTime Player from your Applications folder.
  2. From the menu bar, choose File > New Screen Recording. Or press Control + Command + N.
    • If you see the onscreen controls described above, screen recording on your Mac is performed by the Screenshot app. Follow the steps in the previous section.
    • If you see the Screen Recording window described below, screen recording on your Mac is performed by QuickTime Player. Continue to the next step.
  3. Before starting your recording, you can click the arrow next to the Record button to change the recording settings:
    • To record your voice or other audio with the screen recording, choose a microphone. To monitor that audio during recording, adjust the volume slider. If you get audio feedback, lower the volume or use headphones with a microphone.
    • To show a black circle around your pointer when you click, choose Show Mouse Clicks in Recording.
  4. To start recording, click the Record button and then take one of these actions:
    • Click anywhere on the screen to begin recording the entire screen.
    • Or drag to select an area to record, then click Start Recording within that area.
  5. To stop recording, click the Stop button in the menu bar, or press Command + Control + ecc (Escape).
  6. After you stop recording, QuickTime Player automatically opens the recording. You can now play, edit, or share the recording.

Learn more about using QuickTime Player

Delete an app

Finder > Applications, click on the application, then press Command + Delete.

External tips and tricks

macOS Tips & Tricks

Removing a file from quarantine

If you try to open a file and get the message “Apple could not verify … is free of malware” and you’re sure the file is safe, you can mark it as safe.

For an install programs

Otherwise:

xattr -d com.apple.quarantine <file-name>

Or, enter this, with a trailing space.

xattr -d com.apple.quarantine

Then drag the file from Finder into the Terminal window. THe Terminal will fill in the file path. Then press return.

If you accidentally issue xattr -d a second time for the same file, xattr will print a message like this:

xattr: <file>: No such xattr: com.apple.quarantine

Finder

Control what a new Finder window shows

Finder > Settings > General: Change the value of New Finder windows show.

Show path

To display the path as text, instead of a series of icons.

defaults write com.apple.finder _FXShowPosixPathInTitle -bool true && killall Finder

Finder copy path

Finder directory navigation shortcuts

Selecting files in Finder

Select a file by clicking on it. To select additional files, either Command + Click on each additional file or, to select a range of files, Shift + Click on the last file in the range.

Moving files in Finder

Moving files method one

First select a file or files, then Command + C, then select the target, and click either click on Edit > Paste or right click on the source then click on Paste. (Do not use Command + V as that will copy the files.)

Moving files method two

This doesn’t work and I don’t know what I left out or mistyped.

First select a file or files. Next press Command + Click on one of the selected files and drag the files to the desired directory, which can be in the same Finder windows, another, Finder window or the desktop. Once you start dragging, you can release the Command key.

To cancel the move, drop the selected file(s) back in their original location.

Moving files method three

Right click (two fingers on the trackpad) on the source, click on Copy. Right click on the source, click on Paste.

Controlling what app opens a file

To make this change permanent, even if the desired app is listed, do not pick it from the list. Instead, click on Other..., find the desired app, check the box Always Open With, then click on Open.

This changed the default app used to open this file and does not change the default app for the file type.

For more information, see the ResForge project, the Resource Fork wiki, and File system formats available in Disk Utility on Mac.

Controlling the default app for a file type

MacOS shell weirdnesses

See /etc/bashrc which leads to /etc/bashrc_Apple_Terminal.

MacOS file system weirdness

Access to some directories where ls(1) shows the user should have access give “Operation not permitted”, even with root access.

ls -ld -@ ~/Library/Safari
drwxr-xr-x@ 44 bvoris  staff  1408 Mar  9 16:38 /Users/bvoris/Library/Safari
  com.apple.quarantine  -1

: ls ~/Library/Safari
ls: Library/Safari: Operation not permitted

: sudo ls ~/Library/Safari
ls: Library/Safari: Operation not permitted

From ls(1)

If the file or directory has extended attributes, the permissions field printed by the -l option is followed by a ‘@’ character. Otherwise, if the file or directory has extended security information (such as an access control list), the permissions field printed by the -l option is followed by a ‘+’ character. If the -% option is given, a ‘%’ character follows the permissions field for dataless files and directories, possibly replacing the ‘@’ or ‘+’ character.

Permission is granted in System Settings > Privacy & Security.

MacOS network configuration

DNS configuration

/etc/resolv.conf, which is a symbolic link to /private/etc/resolv.conf, which is a symbolic link to ../var/run/resolv.conf contains this:

#
# macOS Notice
#
# This file is not consulted for DNS hostname resolution, address
# resolution, or the DNS query routing mechanism used by most
# processes on this system.
#
# To view the DNS configuration used by this system, use:
#   scutil --dns
#
# SEE ALSO
#   dns-sd(1), scutil(8)
#
# This file is automatically generated.

The nameserver values listed in resolv.conf come from System Settings > Network > Details (of current connection) > DNS

Users and groups

MacOS does not use /etc/passwd.

To edit a user from Settings > Control + Click on the user name. “Advanced Options…” should appear. Click on it.

From the command line, use dscacheutil and dseditgroup and maybe chsh and passwd

Change shell

sudo chpass -s /opt/local/bin/bash bvoris

Without sudo, this will fail with "chpass: /opt/local/bin/bash: non-standard shell"

dscacheutil -q group -a name _developer
dscl . -read /Groups/_developer
dscacheutil -q user -a name bvoris

The output of this next command includes an encoded picture, so its very long.

dscl . -read /Users/bvoris

members script

#!/bin/bash

# members -- list all members of a group
#
# SYNOPSIS
#   members groupname
#
# http://superuser.com/questions/279891/list-all-members-of-a-group-mac-os-x
#  by Arne
# Expected to work on Mac OS 10.5 and newer, tested on 10.6 and 10.7.
# It could be rewritten to work on 10.4 by using "dseditgroup -o checkmember"
# instead of "dsmemberutil checkmembership".
# By using dseditgroup, the script could also be extended to handle
# other Directory Service nodes than the default local node.
#

the_group="$1"
# Input check and usage
  if [[ $# != 1 || $1 == -* || $1 =~ [[:space:]] ]]; then
    echo "Usage: ${0##*/} groupname" >&2
    echo "Lists all members of the group." >&2
    exit 64
  elif (dsmemberutil checkmembership -U root -G "$the_group" 2>&1 \
    | grep "group .* cannot be found") >&2; then
    exit 1
  fi

# Check every user
exec dscl . -list /Users \
  | while read each_username
  do
    printf "$each_username "
    dsmemberutil checkmembership -U "$each_username" -G "$the_group"
  done \
    | grep "is a member" | cut -d " " -f 1

man pages

Apples supports both man and info but man -k (search for a command) and whatis always outputs “nothing appropriate”.

Try man makewhatis and man whatis.

: echo $MANPATH
:/usr/share/man
 sudo /usr/libexec/makewhatis

fails with "makewhatis: /usr/share/man/whatis.tmp: Read-only file system".

/opt/local/bin/whatis cp
whatis: nothing appropriate
/usr/bin/whatis cp

gives lots of ugly output (groff errors?) but eventually shows cp(1)

port man-db

sudo port install man-db

Outputs this:

  found in man-db-2.13.0/config.log
--->  Building man-db
--->  Staging man-db into destroot
--->  Installing man-db @2.13.0_0
--->  Activating man-db @2.13.0_0
Error: Failed to activate man-db: The following ports have active files that conflict with man-db's:
mandoc @1.14.6_0
  /opt/local/bin/apropos
  /opt/local/bin/man
  /opt/local/bin/whatis
  (... 3 more not shown)
Image error: Conflicting file(s) present. Please deactivate the conflicting port(s) first, or use 'port -f activate man-db' to force the activation.
    while executing
"throw registry::image-error $msg"
    ("foreach" body line 35)
    invoked from within
"foreach file $imagefiles {
                incr progress_step
                _progress update $progress_step $progress_total_steps
                se..."
    invoked from within
"registry::write {
            foreach file $imagefiles {
                incr progress_step
                _progress update $progress_step $progress_..."
Error: See /opt/local/var/macports/logs/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_textproc_man-db/man-db/main.log for details.
Error: Follow https://guide.macports.org/#project.tickets if you believe there is a bug.
Error: Processing of port man-db failed