AppleScript to copy selected text to the clipboard and passes it as an argument

I am trying to make a word counter shortcut in the shortcuts app where the text can just be selected/highlighted instead of copied to the clipboard manually.

I have the word counting part figured out but need a script that copies the selected text to the clipboard and passes it to the next action.

Thanks in advance!

You know Word has a built-in word count feature

I do. The word counter I’m trying to put together is to be used in other apps, wherever text selection is possible.

I’m not sure about Shortcuts I do not use it.
But I believe you could do it with Automator Services.

  1. Highlight text
  2. Right click
  3. Pick the Automator Services Script

The highlight text become the input in your Automator Services Script.

Not every application supports selections in AppleScript, e.g. TextEdit.

When I want to get the selection there, I script command-c, like so:

tell application "System Events" to key code 8 using command down -- copy

Save a script containing only that line in the user scripts menu and it should be available with whatever the frontmost app is. Or, you could include its function in your other script.