Mac OS X Tips

Installation Details

grep OSInstaller /private/var/log/install.log will give details of installation actions, including Time Machine restore operations.

less /System/Library/CoreServices/SystemVersion.plist will show the version of the installed operating system.

General

To have apps re-open their windows next time they're run (or more accurately, stop them being automatically closed on quitting)...

In macOS 10.12 Siera: System Preferences > General > Close windows when quitting an app and clear the checkbox.

https://stackoverflow.com/questions/18932534/xcode-5-how-to-enable-reopen-last-projects-windows

Time Machine

When Time Machine backups are being performed to a Synology Diskstation NAS, the backups are accessible as files under /Volumes/Time Machine Backups/Backups.backupdb/. Use sudo -i in a terminal to become root to view the files.

Purgeable Disk Space

When you use the right-click Get Info option in finder on a drive, it shows a total amount of space that is available and in brackets how much of that space is purgeable. If you use the df -h command in a terminal, it'll show the actual amount of space available.

Time Machine may create local snapshots of backups. The space used by these backups are included in the calculation of the purgeable space. In theory, macOS manages the purgeable space and removes the local snapshots as space is needed. However, it doesn't always free up space in a timely fashion. If you need the space freed more quickly and don't need the local snapshots, you can use the tmutil command line utility to recover the space.

Read the About Time Machine local snapshots – Apple Support article to understand what you may be losing by deleting these snapshots. Use the info tmutil for more information.

You can request tmutil to free up space using the thinlocalsnapshots option, e.g. to request 100GB of free space. The bash expression $((1024**3 * 100)) is a calculation, 1024 to the power of 3 (equals 1 Gigabyte) multiplied by 100 giving 100GB. The parameter after the disk space amount request is 'urgency' with valid values of levels 1-4. It's probably a good idea to temporarily disable backups whilst you're trying to recover some disk space.

$ df -h /
$ tmutil listlocalsnapshots /
$ tmutil thinlocalsnapshots / $((1024**3 * 100)) 1
$ df -h /

Alternatively, you can delete specific local snapshots:

$ tmutil listlocalsnapshotdates
$ tmutil deletelocalsnapshots 2023-09-19-142355

or just delete them all:

$ tmutil deletelocalsnapshots /

Disable Startup Sound/Chime

  1. Mute the sound before shutdown, and un-mute after startup or;

  2. Press and hold the mute key immediately after pressing the power button to start your iMac.

-- Frank Dean - 29 Jun 2017

View Hidden Files in Finder

$ defaults write com.apple.finder AppleShowAllFiles Yes

Relaunch Finder by holding the options key and right-clicking the Finder icon in the launch bar and selecting the Relaunch option.

Hide them again:

$ defaults write com.apple.finder AppleShowAllFiles No

Disable Help Window Always On Top

$ defaults write com.apple.helpviewer DevMode -bool true

Close and re-open any help windows

Enable always-on-top again:

$ defaults write com.apple.helpviewer DevMode -bool false

Safari

Manually Clearing Safari Private Data

Under Safari > Preferences > Privacy > Manage Website Data... deleting individual websites that have a database fails in that they reappear almost immediately after the delete.

To remove them, delete their contents under ~/Library/Safari/Databases.

Ref:

View Saved iMessage Chats

This note applies to macOS 10.12.5 (Sierra)

  1. Open ~/Library folder by clicking on the Go menu item in the Folder application. Hold down the options key to reveal the Library option and then select it.

  2. Navigate to ~/Library/Containers/com.apple.iChat/Data/Library/Messages/Archive

  3. Locate the recipient in one of the sub-folders named by date.

  4. Open the file with the ichat file extension by choosing the Open option from the context menu or by double-clicking it.

  5. The conversation will be loaded in a separate window in the Messages application and also in the Messages window.

  6. Optionally, close the separate conversation window.

Ref: https://apple.stackexchange.com/questions/173640/how-to-re-open-a-conversation

Default Shell

The default shell on modern macOS is zsh. This can be changed in System Settings... > Users & Groups. Ctrl-click the user name and choose Advanced Options... and select the preferred shell.

See:

-- Frank Dean - 02 Mar 2024

Git

Install by running the git command from a terminal. When given the option, install Xcode.

Emacs

A non-GUI version of Emacs is installed in recent versions of Mac OS X.

The most recent GUI version can be installed from MacPorts.

$ sudo port install emacs-app

https://www.emacswiki.org/emacs/EmacsForMacOS

Emacs add-ons

The following add-ons can be installed from MacPorts:

  • magit
  • markdown-mode.el

Pandoc

Pandoc can be installed form MacPorts:

$ sudo port install pandoc

If you also want to use Pandoc to create PDF documents, install TeX Live:

$ sudo port install texlive texlive-latex-extra

Python

Where multiple versions of Python have been installed, a specific version can be specified with:

$ sudo port select --set python python27

QLandkarte GT

  • Install XQuartz
  • Install MacPorts
  • sudo port install gdal +poppler
  • sudo port install qlandkartegt

coreutils

Installing coreutils from MacPorts (see InstallingMacPorts) installs the coreutils binaries prefixed with a 'g'. E.g. use gshred for shred.

http://superuser.com/questions/617515/using-shred-from-the-command-line

Sending E-mails from the Command Line via SMTP

The easiest way is to install msmtp as a drop-in replacement for sendmail, but also providing the ability to implement SMTP Auth to send the e-mail to your mail provider for handling.

It can be installed from MacPorts.

$ sudo port install msmtp

Example usage in a Bash script:

#!/bin/bash
/opt/local/bin/msmtp -t <<EOF
To: "Recipient name" <recipient@example.com>
From: "Sender name" <user@example.com>
Subject: Test message

Leave a blank line after the header as per https://www.ietf.org/rfc/rfc0822.txt

Optional signature following line consisting of two hyphens followed by a
space and end of line, as per https://tools.ietf.org/rfc/rfc3676.txt
-- 
my signature
EOF

-- Frank Dean - 6-Feb-2020

TLS Certification Verification Errors

You can examine the SMTP server's certificate with:

$ openssl s_client -connect mail.example.com:25 -starttls smtp

Piping it back through openssl will show the dates, or use the -text option instead of -dates to see more information:

$ openssl s_client -connect mail.example.com:25 -starttls smtp | openssl x509 -noout -dates

If the validation error is in the certificate chain: e.g.

msmtp: TLS certificate verification failed: certificate 3 of 4 has expired

Write the full chain to a file:

$ openssl s_client -connect mail.example.com:25 -showcerts -starttls smtp >cert-chain.crt

Use a text editor to extract the (in this case) the third certificate from the output file, save it as a separate file and pass it to openssl:

$ openssl x509 -noout -text <cert-03.crt

If part of the chain is failing and you are absolutely certain that the server certificate is valid, obtain the fingerprint with:

$ msmtp --serverinfo --tls --tls-certcheck=off

Specify the fingerprint with the tls_fingerprint option in the msmtp configuration file.

-- Frank Dean - 6-Jun-2020

Watching Web Pages for Changes

urlwatch can be installed from MacPorts.

$ sudo port install py-urlwatch

If using msmtp as described above, modify the following parameters in the report section of urlwatch.yaml to enable sending an email when a change is reported.

report:
    email:
        enabled: true
        from: 'sender@example.com'
        html: false
        method: sendmail
        sendmail:
            path: /opt/local/bin/msmtp
        subject: 'Urlwatch {count} changes: {jobs}'
        to: 'recipient@example.com'

Create a urls.yaml file with entries to watch specific URLs, e.g.:

filter:
- xpath: //div[contains(@class,"release-header")]//div/a[1]/text()
kind: url
url: https://github.com/yarnpkg/yarn/releases/latest
---
filter:
- xpath: //a[last()]
- html2text: re
kind: url
url: https://nodejs.org/dist/latest-v10.x/
---
filter:
- xpath: (//div[contains(@class,"featureborder")]/h2[@class="featuretitle"])[1]/text()
kind: url
url: https://gnucash.org/download.phtml
---
filter:
- xpath: (//body//p/b)[1]/text()
kind: url
url: https://www.gimp.org/downloads/
---
filter:
- xpath: //div[contains(@class,"release-header")]//div/a[1]/text()
kind: url
url: https://github.com/transmission/transmission/releases/latest
---
filter:
- xpath: (//div[contains(@class,"download")]/a)[2]/span/text()
kind: url
url: https://www.adium.im
---
filter:
- xpath: (//article[contains(@class,"status-publish")]//h2)[1]/text()
kind: url
url: https://www.audacityteam.org/download/mac/
---
filter: html2text,grep:^(Download.*version|[0-9]+\))
kind: url
url: https://josm.openstreetmap.de
---
filter:
- xpath: (//div[@id="mac"]/p/a)[1]/text()
kind: url
url: https://apps.ankiweb.net
---
filter:
- xpath: (//a[contains(@class,"dl_download_link")])[last()]//@href
kind: url
url: https://www.libreoffice.org/download/download/
---
kind: url
url: https://github.com/macports/macports-ports/blob/master/devel/yarn/Portfile
filter:
- xpath: //td[contains(@class,"blob-code") and starts-with(text(),'github.setup')]/text()
---
kind: url
url: https://github.com/macports/macports-ports/blob/master/devel/nodejs10/Portfile
filter:
- xpath: //td[contains(@class,"blob-code") and starts-with(text(),'version')]/text()

Sadly, the above examples will no doubt quickly become out-of-date, so use them as a potentially helpful guide to some of the ways of using XPath. Note also, as of version 2.17, urlwatch does not support XPath 2.0 expressions.

Check the output of the filters with:

$ urlwatch-x.y --test-filter 1
$ urlwatch-x.y --test-filter 2

Run a check:

$ urlwatch-x.y

Automate running daily with a launchctl job file with a plist file extension e.g.:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <key>Disabled</key>
    <false/>
    <key>Label</key>
    <string>com.example.urlwatch</string>
    <key>Program</key>
    <string>/opt/local/bin/urlwatch-3.8</string>
    <!-- See man launchd.plist -->
    <key>StartCalendarInterval</key>
    <array>
      <dict>
        <key>Minute</key>
        <integer>11</integer>
        <key>Hour</key>
        <integer>7</integer>
      </dict>
    </array>
    <key>ProcessType</key>
    <string>Background</string>
  </dict>
</plist>

Load it with:

$ launchctl load launch.plist

Unload it with

$ launchctl unload launch.plist

Note: macOS 11.x (Big Sur) may give the following error after running the command:

Load failed: 5: Input/output error

If so, try running the unload command, then re-try the load command.

-- Frank Dean - 6-Feb-2020

Platypus

A developer tool to create native Mac OS X applications for interpreted scripts, e.g. Perl, Ruby and Python.

http://sveinbjorn.org/platypus

Installing OpenJDK

See MacOSXOpenJDK.

Installing Oracle JRE

The JRE (8u111) does not create symlinks or binaries for java on the path. Oracle recommend installing the full JDK to use the Java command line tools.

See When I try to use java from the command line, why doesn't it work?

Uninstalling Java Runtimes

See https://www.java.com/en/download/help/mac_uninstall_java.xml

  1. Remove the Java Applet Plugin folder:

    $ sudo rm -rf /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/
    
  2. Remove the symbolic link for the system preferences Java control panel

    $ sudo rm -f /Library/PreferencePanes/JavaControlPanel.prefPane
    
  3. For each user:

    $ rm -rf ~/Library/Application\ Support/Java/
    

    and/or

    $ rm -rf ~/Library/Application\ Support/Oracle/Java/
    

To uninstall JDKs, remove them from under /Library/Java/JavaVirtualMachines.

-- Frank Dean - 11 Jan 2017

Setting JAVA_HOME

See the man page for java_home which includes examples under the USAGE section at the end.

-- Frank Dean - 11 Jan 2017

Remote Debugging Javascript on iPad

See iOSTips.

Application Defaults

See man defaults

As an example, to see all the defaults for GnuCash (version 2.6.13):

$ defaults read org.gnucash.Gnucash

to remove entries, e.g. a most recently used (MRU) file from the history:

$ defaults delete org.gnucash.Gnucash "/org/gnucash/history/file4"

to see the updated interval (in seconds) for Google Update Agent:

$ defaults read com.google.Keystone.Agent checkInterval
18000

to change the update interval (in seconds) to every 24 hours (60 * 60 * 24):

$ defaults write com.google.Keystone.Agent checkInterval 86400

X11/XQuartz

Language

Add the following to .profile using one of the character encodings shown when running locale -a:

export LC_ALL=en_GB.UTF-8
export LANG=en_GB.UTF-8

Make sure .profile (and .bashrc) are read for a bash shell. Add the following to .bash_profile:

if [ -r ~/.bashrc ]; then . ~/.bashrc; fi
if [ -r ~/.profile ]; then . ~/.profile; fi

-- Frank Dean - 30 Mar 2017

Log Rotation

$ man newsyslog
$ man newsyslog.conf

-- Frank Dean - 4 Dec 2019

System Integrity Protection

To check the status of System Integrity Protection (SIP):

$ csrutil status

Which, when enabled, will output:

System Integrity Protection status: enabled.

-- Frank Dean - 26 Sep 2019

Checking DMG Signatures

To check the code signing of a DMG file:

$ codesign --verify --verbose $PATH_TO_DMG_FILE

-- Frank Dean - 26 Jun 2020

Miscellaneous

ffmpeg

Converting ogg encoded files to aac.

Install ffmpeg and libfdk-aac using Macports nonfree variant:

$ sudo port install ffmpeg +nonfree

Then convert with:

$ ffmpeg -i $file -acodec libfdk_aac $file.m4a

or, include tags:

$ ffmpeg -i $file -acodec libfdk_aac -map_metadata 0:s:0 $file.m4a

or convert a set of files:

$ for file in *.ogg; do ffmpeg -i $file -acodec libfdk_aac -map_metadata 0:s:0 $file.m4a; done;

Burn ISO to CD/DVD

If burning by selecting the ISO in Finder (right-click -> Burn xxx to Disc...) does not work:

$ man hdiutil
$ hdiutil burn my.iso
    Preparing data for burn
    Opening session
    Opening track
    Writing track
    ...............................................................................
    Closing track
    ...............................................................................
    Closing session
    ...............................................................................
    Finishing burn
    Verifying burn…
    Verifying
    ...............................................................................
    Burn completed successfully
    ...............................................................................
    hdiutil: burn: completed

-- Frank Dean - 29 Apr 2020

Report Sleep Activity

$ pmset -g log | grep -i sleep
$ pmset -g stats
$ man pmset

-- Frank Dean - 3 May 2020

Spell Checker

Unlearn Spellings

You should be able to Control-click the wrongly spelt word and choose the 'Unlearn Spelling' option to unlearn it. As of macOS 10.15.7 (Catalina), it shows up as the first option in the context menu. However, it seems unreliable. It may work more reliably in the TextEdit application.

See Check spelling and grammar on Mac - Apple Support

Local spellings that have been "learnt" are stored in a text file, ~/Library/Spelling/LocalDictionary. If the 'Unlearn Spelling' option isn't shown in the context menu, simply edit the text file and correct or remove words as appropriate. Restart the /System/Library/Services/AppleSpell.service/Contents/MacOS/AppleSpell process, or just reboot for the changes to take effect.

You can use the 'Activity Monitor' application to terminate the AppleSpell process.

  1. Select the CPU tab.

  2. Type 'spell' in the search box.

  3. Select AppleSpell from the list.

  4. Click on the information icon (the letter 'i' in a circle). A dialog is displayed showing AppleSpell in the title bar.

  5. Click the Quit button. Three options are displayed, 'Cancel', 'Force Quit' and 'Quit'.

  6. If terminating it with the 'Quit' option does not work, use the 'Force Quit' option.

  7. After a short delay (in the order of a few seconds) the title bar changes to include (Terminated).

  8. The service will be automatically restarted when the spell checker is next used.

-- Frank Dean - 21 Feb 2021

Software Update Hangs

Unfortunately, there seem to be many different reasons why this may fail.

I had this issue trying to upgrade from Big Sur to Monterey. The following resolved it:

Restart the software update daemon with the following command:

$ sudo launchctl kickstart -k system/com.apple.softwareupdated

Go back into the Software Update dialog and it may work.


-- Frank Dean - 30 Jun 2016

Related Topics: AppleMaciBook, InstallingKitlistMacOSX, InstallingMacPorts, iOSTips, MacKeyboardTips, MacOSXOpenJDK, PostgreSQLMacOsX, PostgreSQLmacOS, VncTips