A slashing odyssey

In the Mastodon announcement of my last post, I included some text that was struck through:

☃️ A shortcut I use to c̸h̸e̸a̸t̸ a̸t̸ play the NY Times Connections game. https://leancrew.com/all-this/2025/04/play-connections/

This was not done with <s> tags. Those use a horizontal line to strike through, not diagonals, and besides, Mastodon doesn’t support HTML tags.

Instead, each struck-through character was followed by the Long Solidus Overlay combining character. Combining characters overstrike the previous character, which is just what I wanted.

I used to have a Service that created struck-through text like this, but that was long ago and was written in Python 2, which I don’t use anymore. For the particular seven characters shown above, I just copied the combining solidus character from its FileFormat page and pasted it after each character I wanted struck through. That was the quickest way to get it done for a one-off.

But I do like making jokey strikethroughs like that, so a new Quick Action

1 for doing it seemed in order. Because the world has changed since that post in 2014, it seemed best to use Shortcuts to invoke a Python 3 script and save it as a Quick Action.

Here’s Shortcuts with the Quick Action:

Slash Text Shortcut

The Python code in the Run Shell Script step is this:

from sys import stdin
from string import whitespace

orig = stdin.read().rstrip('\n')
print(''.join(c if c in whitespace else c + '\u0338' for c in orig), end='')

I found that Shortcuts was adding a linefeed to the end of the selected text, so that’s why the rstrip('\n') method was added to read. The generator expression inside the join function uses Python’s somewhat tricky conditional expression, which puts an if-then-else on a single line but in then-if-else order. The generator expression adds the solidus combining character (\u0338) after each character that’s not whitespace.

Using this Quick Action is simple: select the text you want to strike through, control-click and choose Slash Text from the Services submenu. Like this:

Choosing Slash Text from the Services submenu

When I tested the Quick Action in some common text editing applications, like BBEdit, Mail, Pages, TextEdit, and even Stickies, it worked just fine. But you know I wouldn’t write a sentence like that if there weren’t another shoe waiting to drop. And you’re right. It didn’t work in Mona or Messages, the two apps in which I’d use it most frequently.

Error alert from Messages

Why did it fail in those apps? I have no idea, but whatever the reason, it was no good to me in its current state. What to do?

My first thought was to revert to using Automator to make the Quick Action. It’s supposed to be getting phased out in favor of Shortcuts, but it still works. Here’s my Slash Text Automator workflow:

Slash Text Automator workflow

The shell script is now run via bash:

source $HOME/.bashrc

slashtext

I couldn’t just use the Python code in Automator because it doesn’t allow me to use either /usr/bin/python3 or my Homebrew-installed Python as the shell. The shells it allows are

These are apparently unchangeable because they’re in a plist file on a read-only partition. Since I don’t have a Python executable in /usr/local/bin,

2 my workaround was to save my Python script as a file, slashtext, in my $PATH and call it via bash. The source code of slashfile is the same Python code as before but with a shebang line:

#!/usr/bin/env python3

from sys import stdin
from string import whitespace

orig = stdin.read().rstrip('\n')
print(''.join(c if c in whitespace else c + '\u0338' for c in orig), end='')

Going back to the shell script, my .bashrc file sets my $PATH when I work in the Terminal, so sourceing it gives the Quick Action my usual environment. That’s why I can call slashtext directly in the following line.

This Quick Action worked in every application I tried, an indication that Shortcuts still has a ways to go before it’s as reliable as Automator.

Speaking of reliability, my final thought was that I should give up on Quick Actions entirely and just make a Keyboard Maestro macro (download). Peter Lewis’s app is more trustworthy than most of what Apple’s put out recently. With the Python script already written, the only real work was adding some actions on either side of the script to deal with the clipboard. Here’s a screenshot of the macro:

KM Slash Text

Both the rstrip('\n') and the end=' ' are unnecessary here because no linefeed is added to the input and Keyboard Maestro strips trailing linefeeds from the output by default. But leaving those bits of code in doesn’t hurt anything.

Typing ⌥⇧⌘/ is certainly faster than control-clicking and navigating the Services submenu. Will I remember this keystroke combination? Probably not, but since I have KeyCue installed, I don’t need to. All I have to do is press the Control key, wait a couple of seconds for the KeyCue window to appear and choose Slash Text.

KeyCue window

That’s still easier than using the Services submenu.

By the way, Keyboard Maestro allows you to export macros as Text Services. For this one you’d first have to change the input of the shell script to the %TriggerValue% token and delete a couple of the clipboard actions, but otherwise the macro would be the same. I didn’t do it that way because I’d already convinced myself to avoid Quick Actions/Services.

If you really want to stick with Apple-supplied software while still having a fast way to slash text, you can build the Automator workflow, save it as a Quick Action, and then set a keyboard shortcut to it via the System Settings app. I’d use that solution if Peter Lewis or the Ergonis people decided to retire and no one took up their apps.

Update 6 Apr 2025 6:25 PM
John Gruber shared a Keyboard Maestro macro he uses to skip over the complicated mousework needed to access the Services menu. The macro, run via a keystroke combination, opens the submenu but doesn’t select any command. He then starts typing, which selects the Quick Action he wants, and hits Return to execute it. This takes longer to describe than it takes to do.

I like the hybrid nature of this approach. By tucking Quick Actions away in the Services menu, Apple has made them hard to get at. This macro brings them out into the light and requires the memorization of only one keystroke combination. It parallels how I use KeyCue to remind me of Keyboard Maestro macros whose keyboard shortcuts I’ve forgotten.


  1. Why did Apple decide to change their name from Services to Quick Actions even though they’re still invoked from the Services menu? Maybe it was to distinguish the action from the menu, but if that were the case, why do we now build shortcuts in the Shortcuts app?