Idea: I select text, and it gets replaced with <sometag>selected text</sometag>.


on run {input, parameters}

tell application "System Events" to keystroke "<tag>[what should go here]</tag>"

    return input
end run
  • "I select text, and it gets replaced with selected text." So, isn't that replacing the text with itself ? Otherwise, I don't get it.
    – CJK
    Oct 25, 2019 at 10:34
  • I have edited it. Some elements were hidden by stack. Oct 25, 2019 at 10:43
  • 2
    Thanks. That's easy, though I don't have a computer currently so you'll need to suffer with an absence of screenshots in my answer, which I'll type out now.
    – CJK
    Oct 25, 2019 at 10:46
  • Thank you, this will literally save hours. Oct 25, 2019 at 10:53

1 Answer 1


Briefly, have your workflow accept Text from Any Application and check the box that is labelled something like Output Replaces Selection.

Then, all you need is a single Execute AppleScript action, in which you should replace any example code with this:

on run {input as text}
    return ["<sometag>", input, "</sometag>"] as text
end run

which can also be written like this:

on run {input as text}
    return "<sometag>" & input & "</sometag>"
end run

The workflow would need to be saved as a Service or Quick Action, and then be activated in System Preferences where other "Services" are listed.

You must log in to answer this question.

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