How to replace the currently selected text in Applescript? How does Devontechnologies WordServices' do it?

apple.stackexchange https://apple.stackexchange.com/questions/327842

  •  21-04-2021
  •  | 
  •  

Domanda

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.

È stato utile?

Soluzione

You could use an Automator contextual workflow service.

  1. Open Automator select Contextual Workflow enter image description here

  2. Enter the following settings

    • Workflow Receives: text
    • In: Any Applicaition
    • Check Output replaces selected text
  3. Add the AppleScript Action

enter image description here

  1. The selected text will be in the input variable. It will return the input 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.

enter image description here

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a apple.stackexchange
scroll top