How to use selected text in apple script? I want to add text before and after it
Idea: I select text, and it gets replaced with <sometag>selected text</sometag>
.
Code:
on run {input, parameters}
tell application "System Events" to keystroke "<tag>[what should go here]</tag>"
return input
end run
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.