Things I Have Written

Regular Expressions and Shortcuts, Part 4

This post is part of a series on Regular Expressions and their applications in the Shortcuts app.

Regular Expressions and Shortcuts, Part 1

Regular Expressions and Shortcuts, Part 2

Regular Expressions and Shortcuts, Part 3

Regular Expressions and Shortcuts, part 3.5

Using regular expressions in shortcuts is pretty simple. The Match Text block will always treat the text to match as a regular expression, and the Replace Text block has an option to treat the text to replace as a regular expression.

Shortcut actions to grab file names from a directory listing supplied by Secure Shellfish

In the above image, the Match Text block takes the directory contents list, which looks like this:

hugo-files/data/links/cars.json
hugo-files/data/links/podcasts.json
hugo-files/data/links/language.json
hugo-files/data/links/apps.json
hugo-files/data/links/security.json
hugo-files/data/links/linux.json
hugo-files/data/links/programming.json
hugo-files/data/links/apple.json

And performs a match to grab just the file name without the file extension, using the regular expression I talked …

(Read More)

 This Is a Rare Prototype of the First Apple Watch

If these watch prototypes are real, this is pretty cool. They look so fat and chunky now!

Giulio Zompetti, a 27-year-old from Northern Italy, told Motherboard that he purchased half a dozen early prototypes of Apple Watch recently, and is planning to fix them and sell them for thousands of dollars. Zompetti declined to say where exactly he purchased the devices from, but said they come from e-waste facilities. The prototypes he obtained are all broken, but key components are still intact, making it possible to repair them, he said.

Someday I wish Apple would publish a book of photos of their various prototypes from throughout the years. It would be fascinating to see the differences in initial concepts and final production models.

 Permalink

Random Terminal Message of the Day

Dan Moren posted a Terminal Message of the Day tip on Six Colors a few days ago, and I decided I would configure my Mac with a MOTD as well. However, I want a random one from a list every time I open a terminal rather than seeing the same one over and over.

The easiest way to do this is to avoid the /etc/motd file altogether and use a script to read a random line out of a text file and display that when you open a terminal window. There are three parts to this, two of which take all the work: a text file full of messages of the day, a script to randomly grab one, and a means by which to execute it automatically when you open terminal.

Find a place on your Mac you want to store scripts, if you don’t already have one. …

(Read More)

Regular Expressions and Shortcuts, Part 3.5

This post is part of a series on Regular Expressions and their applications in the Shortcuts app.

Regular Expressions and Shortcuts, Part 1

Regular Expressions and Shortcuts, Part 2

Regular Expressions and Shortcuts, Part 3

Before continuing on and looking at how to integrate the regular expression we’ve been talking about so far into a shortcut, I want to incorporate a piece of feedback from Allister Jenks.

I originally came up with this:

^(?:.+\/){1,}(.+)\.json$

Allister points out that there’s a much more logical and concise way of doing it.

He’s right, of course. The following works perfectly and makes more sense.

^(?:.+\/)+(.+)\.json$

Actually, we don’t even need the + after the first group, thanks to greedy matching. By …

(Read More)

Regular Expressions and Shortcuts, Part 3

This post is part of a series on Regular Expressions and their applications in the Shortcuts app.

Regular Expressions and Shortcuts, Part 1

Regular Expressions and Shortcuts, Part 2

Hi, it’s me again, the guy with the terrible regular expression that I keep yammering on and on about:

^(?:.+\/){1,}(.+)\.json$

Last time I explained how (.+\/){1,} works to match file path directories in a file name, like these:


hugo-files/data
hugo-files/
hugo-files/data/links/

I did not explain, however, why the first part of the regular expression contains ?: inside the first set of parenthesis, like this:

(?:.+\/){1,}

In order to understand this, you have to understand the role of the parenthesis in regular expressions.

First, they do what I said last time they do: group things together for the purposes of applying a subsequent modifier to everything in the group. In our case, because …

(Read More)

Regular Expressions and Shortcuts, Part 2

Last time, I presented a case in which I wanted to take a list of files complete with file path, and extract just the file name without the extension.

So basically, I get a list of file names that come back like this:


hugo-files/data/links/cars.json
hugo-files/data/links/podcasts.json
hugo-files/data/links/language.json
hugo-files/data/links/apps.json
hugo-files/data/links/security.json
hugo-files/data/links/linux.json
hugo-files/data/links/programming.json
hugo-files/data/links/apple.json


And I want to turn it into the following list instead, by getting rid of the directory paths and the .json file extensions:


cars
podcasts
language
apps
security
linux
programming
apple


I do this in my shortcut using a Match Text action with the following regular expression:

^(?:.+\/){1,}(.+)\.json$

It looks mind-bogglingly weird if you’re not used to regular expressions, and certainly someone skilled with them could probably perform the same task with a much more elegant version, but this does the job for me, and it’s really quite simple. …

(Read More)

 Affinity Sale

Right now Affinity Photo and Affinity Designer are 50% off on both iPad and Mac versions. These are incredible bargains for two very powerful programs with feature parity on both devices.

iPad: Affinity Photo: $10 (Reg. $20)

Mac: Affinity Photo: $25 (Reg. $50)

iPad: Affinity Designer: $10 (Reg. $20)

Mac: Affinity Designer: $25 (Reg. $50)

I’m not much of an artist or designer, but I still love and use these regularly, especially on the iPad. And Affinity Photo may be THE best overall photo editing app available on Mac or iPad.

 Permalink

Regular Expressions and Shortcuts, Part 1

Today as I worked on finishing up a major revision to my Blog Post Publish shortcut, it occurred to me that, in a relatively short period of time, I went from struggling to understand regular expressions in general, and how regular expressions worked in Shortcuts in particular, to using them all the time in my shortcuts.

I decided I’d start a series about regular expressions and how to use them productively with the Shortcuts app, not because I’m a genius with regular expressions, but to show that anyone can learn them and that they are indeed useful and powerful when used for creating shortcuts.

Regular Expressions

The term “regular expressions” sounds a little odd, but basically regular expressions are just patterns used for searching text. They are extremely useful for things like extracting specific bits of information from text, for replacing specific things in text, or for validating text input for an app or web …

(Read More)

Data Jar Drag & Drop

Not too long ago, I wrote about JSON file editing using Shortcuts and Data Jar, but now it’s even better. Never one to rest on his laurels, Simon Støvring added drag and drop data insertion as well as keyboard shortcuts with the past couple TestFlight betas.

I made a super short video showing how easy it is to add a new link to a dictionary of links, for example.

Hugo “in slice” versus union queries

As you may remember, I use Hugo sections to structure my site content, and that affects my queries for things like site comprehensive RSS feed and my “Things I’ve written” section, which shows all posts from every section.

The way I have my site set up is that I have several blog sections, starting with Blog, which currently has 3 posts in it that don’t fall under other sections, and then under Blog I have subsections for iOS, Mac, Hugo, and Apple history. Finally, I have a Podcasts section at the same level as Blog.

Podcasts is mostly unused at the moment as it’s where I’m going to make repositories of past (inactive) podcasts, as well as descriptions and links to current and (and future current) podcasts. However, I’ll also post in that section about different episodes of things I’m in.

Anyway, it …

(Read More)