oulipo Posted May 13, 2013 Share Posted May 13, 2013 I've tried to no avail to create a workflow using AppleScript that counts the number of words in the selection of the topmost window, I'd like it to work using a keyword rather than a hotkey in order not to clutter my hotkey, someone knows if this is possible? Or is it only feasible to count the number of words of the current clipboard for instance? (I'd rather have a script that counts the words without having to copy to clipboard) Link to comment
Carlos-Sz Posted May 13, 2013 Share Posted May 13, 2013 You can save the current clipboard content to a string, copy the selection to the clipboard using System Events keystroke command, count the words then put the initial content back to the clipboard. In resume: try set sCurrentCB to get the clipboard end try tell application “System Events” keystroke "c" using command down end tell set sTextToCount to get the clipboard as text —count words here try set the clipboard to sCurrentCB end try oulipo 1 Link to comment
oulipo Posted May 15, 2013 Author Share Posted May 15, 2013 I think this could work actually (from http://www.macworld.com/article/2038095/5-automator-workflows-everyone-should-have.html): on run {input, parameters} set theWordCount to count words of (input as string) display dialog (theWordCount & " words in the selected text." as string) end run Link to comment
fillmoreeast Posted October 25, 2021 Share Posted October 25, 2021 (edited) That works, thank you. I have been looking for a way to do that ... and with a minor modification it can be used as a Universal Action: on run set theWordCount to count words of ("{query}" as string) display dialog (theWordCount & " words in the selected text." as string) end run Edited October 25, 2021 by fillmoreeast Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now