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

I have a script that speaks the temperature from WeatherCat app. How do I limit the number of decimal points it speaks?

tell application "WeatherCat"

set oldCurrentTemperature to 40


repeat

set currentTemperature to ExternalTemp

if oldCurrentTemperature is not currentTemperature then

tell current application

say "Current temperature is"


saycurrentTemperature as string

end tell

end if

set oldCurrentTemperature to currentTemperature

delay 60

end repeat

end tell

Posted on Nov 26, 2015 9:13 AM

Reply
Question marked as Best reply

Posted on Nov 27, 2015 5:17 AM

Hi,



You can use this script:

----------------------------

set oldCurrentTemperature to 40

repeat

tell application "WeatherCat" to set currentTemperature to ExternalTemp

if oldCurrentTemperature is not currentTemperature then

say "Current temperature is " & my limitDec(currentTemperature as string, 1) -- 1 decimal

set oldCurrentTemperature to currentTemperature

end if

delay 60

end repeat


on limitDec(t, numOfDec)

set localDecimalSep to character 2 of (0 as real as text)

set n to the offset of localDecimalSep in t

if n = 0 or n + numOfDec > (length of t) then return t

return text 1 thru (n + numOfDec) of t

end limitDec

2 replies
Question marked as Best reply

Nov 27, 2015 5:17 AM in response to Randy Hust

Hi,



You can use this script:

----------------------------

set oldCurrentTemperature to 40

repeat

tell application "WeatherCat" to set currentTemperature to ExternalTemp

if oldCurrentTemperature is not currentTemperature then

say "Current temperature is " & my limitDec(currentTemperature as string, 1) -- 1 decimal

set oldCurrentTemperature to currentTemperature

end if

delay 60

end repeat


on limitDec(t, numOfDec)

set localDecimalSep to character 2 of (0 as real as text)

set n to the offset of localDecimalSep in t

if n = 0 or n + numOfDec > (length of t) then return t

return text 1 thru (n + numOfDec) of t

end limitDec

I have a script that speaks the temperature from WeatherCat app. How do I limit the number of decimal points it speaks?

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