Shell Scripts in macOS Shortcuts

Automating tedium

I use the uBlacklist browser extension to block domains from search results (I went in depth on this topic previously). While it supports sync with Google Drive or Dropbox, I like to make things harder and refused to use those options, opting for a Git repo instead. Pushing the repo to a remote host like GitHub lets me subscribe to the rules.txt file in all my browsers without needing to log in to anything, and other people can use my opinionated blacklist too.

My method of updating the list looked like this:

  1. Periodically open the uBlacklist settings page on all 3-5 browsers I have it installed on
  2. Open rules.txt in Vim (just because this is the one thing I use Vim regularly for)
  3. Add a new line, and copy/paste the new additions from the browser extension
  4. Google how to quit Vim (just kidding, we use DuckDuckGo round these parts)
  5. Commit the changes to Git and push to remote

As much as I like playing escape room with Vim, this process is getting a little tedious after 5 months. I wrote a little shortcut in macOS to help streamline this:

Screenshot of the Shortcut editor in macOS

Here’s what the shortcut does:

  1. Show a dialog titled, “Add rules from browser” with an input field
  2. Passes the text input to the standard input buffer (stdin) and runs some shell commands:
    1. Change active directory to the folder my uBlacklist repo lives in
    2. Use tee to append the pasted text from stdin to rules.txt
    3. Commit the changes to Git and push to remote

And here’s what my method of updating the list looks like now:

  1. Periodically open the uBlacklist settings page on all 3-5 browsers I have it installed on
  2. Run the shortcut
  3. Copy/paste the new additions from the browser extension
  4. Click “Done”
Screenshot of a dialog titled “Add rules from browser” with a text input field focused

I only shaved off one step here, but it’s much less tedious. And I pinned the shortcut to my Menu Bar for easy access:

Screenshot of the macOS Menu Bar with a dropdown open, showing the shortcut title

Now I want to make a shortcut for starting new blog posts with Hugo, similar to what Simone did with Jekyll.