Welcome to the lab.

Web Excursions for April 28, 2021

Web excursions brought to you in partnership with MindMeister, the best collaborative mind mapping software out there.

This is a very developer-centric excursions post. I spent too long looking at git utilities this week, so you get a bunch of links to cool git stuff I found. If you are, somehow, a developer who doesn’t care about git, be sure to check out the last link anyway.

dandavision/delta
I’ve been using diff-so-fancy with git for a long time, but recently discovered delta. It does way more, with in-line diffs, side-by-side view, and themed output. It even makes copying text out of a diff easier by removing the +/- by default.
Git Town
A set of git utilities that works on top of your favorite workflow (e.g. git-flow) and provides high-level (but simpler) commands for creating and shipping feature branches. I especially like git town sync for updating your working feature branch with all changes from the develop branch and updating remotes in one command.
sobolevn/git-secret: A bash-tool to store your private data inside a git repository.
A git command that allows you to store secret information (credentials, etc.) as encrypted files in a repo. Automates ignoring the original and adding an encrypted copy. Allow others access based on public PGP keys.
MichaelMure/git-bug
Distributed, offline-first bug tracker embedded in git, with bridges for major bug tracking apps (GitHub, Gitlab, Jira, Launchpad). Stores tickets as git objects that can move with a repo without affecting history. It even has a GUI for terminal and a web view.
Mac Dev Survey 2021 Results | Tower Blog
The new Mac Dev Survey results are out. Turns out I’m in some smaller segments these days (I still use Sublime and everyone else uses VS Code). Fun results to look at, though (at least for devs).

Check out MindMeister and start brainstorming, collaborating, and boosting productivity.

Peek brings text selection back to Quick Look (+Giveaway)

There used to be a defaults write trick that would allow you to select text in Quick Look previews, but Apple curtailed it back in 2015. Since then, dragging your cursor on any Quick Look plugin just moves the window. No selection possible, and thus no copy paste from the preview.

Enter Peek, an $8 macOS extension that brings back text selection in Quick Look, at least for source code and Markdown files (which it also syntax highlights and renders, respectively). Both of the latter features do have free alternatives, so the primary draw here is text selection. That, and having your syntax highlighting and Markdown rendering all in one plugin.

In addition to working in Finder, Peek includes support for HoudahSpot, Path Finder and Forklift.

While I have some guesses, I don’t know exactly how Peek is working this magic. All I know is that I’ve really missed text selection in Quick Look, and Peek has solved it. (I’ll also mention that I had some weirdness on my machine that ultimately had nothing to do with Peek, but the developer spent a good week helping me track down the problem. ★★★★★ Great support.)

I have 10 copies of Peek to give away to BrettTerpstra.com readers. Sign up below to enter the drawing. Winners receive a Mac App Store promo code for Peek, value $8 US. Ten winners will be picked at random on Friday, April 30th at 12PM Central.

Entering a giveaway does not subscribe you to any newsletters. If you’d like to get occasional announcements, special offers, and whatever else I come up with, please sign up for the BrettTerpstra.com mailing list separately.

Sorry, this giveaway has ended.

If you can’t wait to get your text selection back, check out Peek today.

Hacking around with Marked’s Streaming Preview

In the last Marked newsletter I wrote a bit about Marked’s Streaming Preview, a feature of Marked that flew under the radar for a few years before starting to gain some traction.

It’s a special window (Preview->Streaming Preview) that watches a private clipboard for updates, updating the preview every time the clipboard contents change. All an app needs to do to interface with it is write Markdown content to the named clipboard, which is easily done from any Swift/Objective-C instance. Normally Marked watches files on the disk for changes, but this special window allows apps to update the preview in Marked without ever writing to disk, and with closer-to-live update speeds. Apps like Drafts, Bear, and The Archive have all implemented it with great results. (I even added some special processing for Bear users, so a majority of the Polar syntax translates to your live Marked 2 preview.)

Because the only trick to using the Streaming Preview is to write to a clipboard, it’s possible to do it in your own scripts as well. You just need to write to a pasteboard named “mkStreamingPreview” and Marked will do the rest.

As an example, Bruno Conte created a Keyboard Maestro macro that will take any currently-selected text and update the Marked preview. Marked has a “Preview Clipboard” command, of course, but that requires copying the text, switching to Marked, and hitting ⇧⌘V — and it opens a new window every time. This macro means you can just select text and hit a keyboard shortcut to live-update the preview window from any application.

Here’s the Keyboard Maestro macro: Copy and Stream to Marked. In order to use it, you’ll need Python’s PyObjC module installed, so if needed, open Terminal and run: pip install PyObjC.

The crux of the macro is in the Python script:

def stream_to_marked(data):
	from AppKit import NSPasteboard
	pb = NSPasteboard.pasteboardWithName_("mkStreamingPreview")
	pb.clearContents()
	pb.setString_forType_(data.decode('utf-8'), 'public.utf8-plain-text')

You can incorporate this kind of script in whatever tools you like. The macro also makes use of Marked 2’s url handler for opening the Streaming Preview externally: just call open x-marked://stream/.

See the docs for more implementation details (including settings a base URL for relative paths). If you come up with cool new ways to use this, I’d love to hear about it. And if you’d like to see Marked’s Streaming Preview integrated into your favorite app, just put the developers in touch with me!

Want to get Marked tips (and special discounts) in your inbox? Sign up for the mailing list!

Fixing the Big Sur proxy icon delay globally

I had previously bemoaned the fact that the proxy icon is now hidden behind a hover delay in Big Sur. In that post, I mentioned that you could remove that delay in Finder using the command defaults write com.apple.Finder NSToolbarTitleViewRolloverDelay -float 0. But that only affects Finder, and you have to repeat it with various bundle identifiers for each app making use of the Big Sur toolbar layout.

I have since realized you can set this globally for all apps in one fell swoop:

defaults write -g NSToolbarTitleViewRolloverDelay -float 0

As far as I can tell, that seems to have done the trick. Just thought I’d update with the new info. I’ve updated the older post as well.

Rewind: Quick reminders in Terminal

I was browsing my gists recently and found one I’d totally forgotten about, which is somewhat ironic given its purpose: scheduling short-term reminders with alarms from the Terminal. I posted it about it back in 2016, but eventually it fell into disuse, as a lot of my just-playing-with-an-idea scripts tend to.

This one was actually pretty cool, though, and I’ve started using it again. You just run something like dontforget to get ready for dinner in 30m in Terminal, and in 30 minutes, you get a reminder in the form of a “ding” and your computer saying “Time to get ready for dinner.” It has LaunchBar integration for large display text.

I don’t know why I ever decided that Bash scripting was the efficient way to write this one. It definitely isn’t. But I stuck with it and updated it a little bit.

You can now use “at 3pm” or “at 10:30am” type strings to set a specific time. The meridian (am or pm) is required. This only works within 24 hours of the current time.

I also added an AppleScript display dialog if you don’t have the LaunchBar integration enabled. Oh, and for some reason I thought it deserved smarter display of the time, so instead of “in 128 minutes,” it says “in 2 hours 8 minutes”.

Contrary to what I wrote in my original post on this, it will actually work fine if you quit the Terminal session you launched it in (assuming you didn’t force it to run in the foreground, but why would you do that, really?).

This little script really isn’t meant to be used for much beyond a quick reminder within a few hours. I use it when I tell my girlfriend I just need to take care of a quick coding problem I thought of in the evening after I’m supposed to be done for the day. “I’ll be back in 20 minutes, I promise.” When I sit down I run dontforget to get back to your beautiful girlfriend in 20m and my Mac will make sure I’m not a liar.

You can find the updated script in the gist. Feel free to leave comments there if you think of additions or fixes it needs! By the way, I’m using Fish as my shell these days, but this works fine as long as it has the bash shebang on the script.

Scripting with sudo on Mac

I was writing up an “advanced scripting” example for the Bunch documentation and realized this tip is useful enough generally to be worth cribbing for a post.

The gist is this: when you need to script a tool that requires administrator privileges, you want to make the process as automated as possible without creating glaring security problems (like including a password in plain text).

An example of why you’d want to do this would be the tmutil command line utility, which allows you to perform Time Machine tasks from the command line. But the enable and disable commands require sudo to work, so pausing Time Machine from a script isn’t as easy as just running tmutil disable. You’d either have do some terribly insecure things to /etc/sudoers, or store your Mac’s most valuable password in plain text in a script. Neither option is good.

Fortunately, macOS has tools built in to make this work. We’ll use a combination of macOS’s Keychain Access and the security command to make running superuser tasks both convenient and secure.

Side note: 1Password has a command line tool that can do something very similar to this, but it requires signing in on the command line. The method below allows you to have a script run in the background, only popping up a password dialog when needed.

A GitHub Stars widget for WordPress

Backstory: my co-host on Overtired, Christina Warren, has a constantly growing collection of repositories she’s starred on GitHub. As a developer advocate for a Big Tech company, she always keeps her finger on the pulse of the new and cool developer stuff, and her stars serve as a curated list of “projects to watch.” It came up on an episode a while ago, and I decided we should have a way to display the latest ones.

The Overtired site uses WordPress, so even though I’m not doing a lot of WordPress development these days, I figured I’d dust off my PHP skills and whip up a plugin for this. It’s pretty barebones, but it does the job, and you can plug in any username to get their latest stars as a widget.

You can see it in action on overtiredpod.com, all the way down in the footer. I actually have never tried it as a sidebar widget, but it’s really simple markup and I’m just assuming it will work.

As with a lot of my little side projects, this one has a finite audience. A convergence of GitHub users who think their stars are worth sharing and happen to be running a WordPress blog. If that describes you, I have just the thing.

Check out the project page for more details. I doubt this will ever see many updates, but it’s tested with WP 5.7 and should be good for the foreseeable future.

WordPress GitHub Stars Widget v1.0.0

A WordPress widget to display your GitHub stars

Published 04/02/21.

Updated 04/02/21. Changelog

DonateMore info…

(I would add this to the WordPress plugin directory for fun, but you still have to set everything up in Subversion and I don’t even have svn installed these days, let alone remember how to use it. If it were a bigger project, I might consider it, but it’s just not worth it.)