2

I have a handful of Automator actions that I'm trying to port to Shortcuts. One of them works like this:

  1. I select some text in an app.
  2. I right-click the selected text and select Services → Prefix With Arrows.
  3. The text now has > on the left edge of every line (I use this to quickly blockquote Markdown text).

All this is handled, at its core, with a short Perl script:

while (<>) {
    $_ =~ s/^(.*)$/\> \1/m;
    print;
}

In Automator, it all looks like this:

Prefix with Arrows Quick Action However, I've been trying to port this action to Shortcuts on Monterey, and I'm not having much success. I've made a new Shortcut, called Stick Arrows In Front, that attempts to replicate the functionality without success. The Perl code is exactly the same. Here's what the rest of it looks like:

Stick Arrows In Front shortcut

However, when I run my Shortcut while having text selected, the text doesn't change at all.

Am I doing anything wrong, and/or should I file a Radar?

2 Answers 2

1

I figured something similar out. The missing piece seemed to be adding a Stop and output action to the end. The wrinkle: this only works after a JXA action (Run JavaScript for Automation), not a Run Shell Script action.

The final Shortcut

The code:

function run(input, parameters) {
    const text = input[0][0];
    const lines = text.split('\n');
    const prefixedLines = lines.map(l => `> ${l}\n`);
    return ''.concat(...prefixedLines);
}

This Shortcut doesn't keep the text selected after it's done running (unlike the Automator action), but that's not a dealbreaker for me.

Additionally, one can just modify input[0][0] and return the entire input variable, but this works just as well for my purposes.

0

I tried your first example using the Notes app, and it did not work until I told it to “Create note with” which worked but you end up with a new note. If you tell it “Show Compose Sheet” you can have it append to the existing note, but you essentially get your text duplicated, the original, and the modified. I’m not sure if that would be helpful, but at least your perl code still works as it did before. And I could only get it to work in the Note app.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .