Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

word count not recognized as integer variable

ok, i have this command:


set mywordcount to do shell script "wc -l < MyFile.txt"


which gives me the number of words of a given txt

with display alert it reports me number 1 when there is one word, number 4 if there are 4 words, etc...


the problem comes when i want to do one action if the file has 1 word, another if it has more than 1...

when i write:


if mywordcount = 1 then

myactions here

else

otheractions here

end if

it doesn't do anything at all...

any ideas?

thanks!

Posted on May 12, 2012 10:49 AM

Reply
4 replies

May 12, 2012 1:51 PM in response to personal_username

the way to do this in applescript is as follows:


set contentsText to read "/path/to/file.txt"

set mywordcount to count of words of contentText


that will return an integer value. if you want to use the do shell script approach, keep in mind that dss always returns text, so you'll want to coerce the text value to an integer:


set mywordcount to (do shell script "wc -l < MyFile.txt") as integer

word count not recognized as integer variable

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