Pragmatism in the real world

Set a file's created date from YAML front matter in macOS

I have a set of Markdown files with YAML front matter that contains a created property containing the date that the file was created. Due to various machinations, the file creation date no longer matches this date, so I thought I'd fix this. Setting created date of a file On macOS, to change a file's creation date you use SetFile which is installed as part of Xcode. Irritatingly, it uses US format dates: SetFile -d… continue reading.

Keep your iPhone passcode secret

TL;DR: If someone sees you enter your passcode on your phone and then steals your phone, they can lock you out of your Apple account, losing access to all your iCloud data, including photos. Treat your phone passcode as carefully as the secret it is. The problem I heard about "A Basic iPhone Feature Helps Criminals Steal Your Entire Digital Life" by Joanna Stern & Nicole Nguyen on The Talk Show and learnt something new.… continue reading.

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.