Pragmatism in the real world

Add TouchID authentication to sudo

Now that I have a TouchID enabled Mac, I want to be able use TouchID for sudo access. There's a pam module available, so it just needs enabling: Edit /etc/pam.d/sudo Add a new line under line 1 (which is a comment) containing: auth sufficient pam_tid.so (Leave all other lines in this file.) That's it. Now, whenever you use sudo, you have the option of using TouchID to authenticate. Scripting it It turns out that whenever… continue reading.

OpenConnect on Mac

One of my clients has recently moved to AnyConnect VPN and I've been having routing problems with the official Mac client. As my colleagues on Linux on the project have not had these issues, I investigated and installed the OpenConnect client. These are my notes after scouring the Internet to set it up how I want it. Installation I used Homebrew: $ brew install openconnect OpenConnect is a CLI tool. If you want a GUI… continue reading.

Keyboard control of Big Sur notification alerts

With the release of Big Sur, my scripts for keyboard control of macOS notification alerts stopped working. With a bit of experimentation and help from Google, I have written new ones. Closing an alert To close a notification alert on Big Sur, conceptually we want to press the X button that appears when you hover over it. The AppleScript to do this is: activate application "NotificationCenter" tell application "System Events" tell process "NotificationCenter" set theWindow… continue reading.

Add Apple Watch authentication to sudo

Note: This article was written in for Intel Macs (not Apple Silicon) that do not have TouchID. If you have a modern Mac, then I recommend Add TouchID authentication to sudo.   Since 1Password added Apple Watch unlock I've wondered if there are other situations when I need to enter my password where it instead require a click of my Watch instead. I recently came across an article about how to make sudo work with… continue reading.

Prevent an external drive from auto mounting on macOS

I have an external drive attached to the USB hub on my Thunderbolt Display that I use to clone my laptop's internal drive every night using the schedule feature of SuperDuper!. At the appointed time, SuperDuper! will mount the external drive, clone the internal drive and then unmount the external drive again which is very convenient. However, whenever I plug in my laptop, the drive automatically mounts. This doesn't particularly worry me, but when I… continue reading.

Keyboard shortcut to mirror displays on a Touch Bar Mac

One feature of the 16" MacBook Pro that was new to me is the Touch Bar. This thing replaces the F-keys with a touch pad that adjusts itself to the app in use in order to provide useful shortcuts you can just touch. This is all well and good, but when presenting, I use the cmd+F1 keyboard shortcut to toggle display mirroring. A useful Stack Overflow answer tells me that I can use cmd+{dim brightness}… continue reading.

Dark and light mode blog images with MarsEdit

As dark mode is more popular than ever now that the iPhone supports it, I've been working out how to get the browser to render a dark image in dark mode and a light image in light mode. It turns out that the way to do this simply is to use the <picture> element like this: <picture> <source srcset="/wp-content/uploads/2019/11/example-image-dark.png" media="(prefers-color-scheme: dark)" /> <source srcset="/wp-content/uploads/2019/11/example-image-light.png" media="(prefers-color-scheme: light), (prefers-color-scheme: no-preference)" /> <img src="/wp-content/uploads/2019/11/example-image-light.png" alt="Description of example image… continue reading.

HTML encode selected text on Mac

When writing blog posts, I write directly in HTML, mostly from habit and because I've not set up mark-up text processing on WordPress. I'm comfortable enough with simple HTML that it's never seemed important enough to sort out, especially with MarsEdit's macros for common HTML tags. One thing that I need to do relatively regularly is to HTML encode code snippets for use in <tt> and <pre> tags. I have been doing this via a… continue reading.

Automatically mounting a network drive on Mac

I have so many photos that I can't store them all on my hard drive and keep them on my NAS. While on my home network, it would be convenient to automatically mount the NAS folder onto my Mac as I keep forgetting before I open Lightroom. Usually I would use automount to do this, but Lightroom cannot see automounted folders, so I decided to use a combination of AppleScript and Keyboard Maestro. Mount a… continue reading.

Keyboard shortcut to Save as PDF on Mac

I regularly print to PDF on my Mac, This is done from the print dialog by selecting Save as PDF from the drop down in the bottom left of the dialog which is a bit of a pain to get using the mouse. I recently discovered that I could create a keyboard shortcut to make this much easier. In System Preferences -> Keyboard -> Shortcuts -> App Shortcuts you can create a keyboard shortcut to… continue reading.