How to replace the currently selected text in Applescript? How does Devontechnologies WordServices' do it?
-
21-04-2021 - |
Question
Devontechnologies offers a collection of services that let's the user perform some common tasks on text (upper case, lower case, ROT13 and so on). They do it without (as far as I can tell at least) using the clipboard (pbpaste/pbcopy).
I have googled a lot about this but the only solutions I have found are based on pbcopy/pbpaste and I want to avoid that. Any suggestions?
I am creating my own service similar to Devon's WordServices that takes an editable piece of text, manipulates it and finally replaces the original text.
Solution
You could use an Automator contextual workflow service.
Enter the following settings
- Workflow Receives: text
- In: Any Applicaition
- Check Output replaces selected text
Add the AppleScript Action
- The selected text will be in the
input
variable. It will return theinput
variable at the end thus replacing the original text with the new text
The workflow can be accessed by selecting text, right clicking, and going to Services.