AppleScript: word count

Hi,

Below is an excerpt from my code where I'm wanting to say that if wordStr has more than 2 words then do this thing or if it has less than/nothing then do the other thing.

I can't seem to be able to get it working correctly. Please help thanks

if wordStr is greater than (2 words) then

set vol to word 2 of textNeeded

set the clipboard tovol

tell application "Numbers" to activate

tell application "System Events"

tell process "Numbers"

keystroke "["

keystrokevol

keystroke "]"

keystroke " "

end tell

end tell

if wordStr is less than (2) then

tell application "Numbers" to activate

tell application "System Events"

tell process "Numbers"

keystroke " "

end tell

end tell

end if

end if

MacBook Pro with Retina display, macOS High Sierra (10.13.4)

Posted on Apr 16, 2018 11:44 PM

Reply
Question marked as Top-ranking reply

Posted on Apr 17, 2018 12:35 AM

Simple:


Replace:

ifwordStr is greater than (2 words) then

with:

if (count words of wordStr) is greater than 2 then

Similar questions

3 replies

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

AppleScript: word count

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.