Applescript that speaks the temperature

Joined
Nov 24, 2015
Messages
1
Reaction score
0
Points
1
This little script gets the current temperature from app WeatherCat.
All works well except that it often tells me the temperature out to 6, 8 or 10 decimal places.
I would like it to stop at 1 decimal place even it the temperature is exactly a number with no decimal places.

Of course I am a no nothing about apple script.

Any help would be appreciated.


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"
say currentTemperature as string
end tell
end if
set oldCurrentTemperature to currentTemperature
delay 60
end repeat
end tell
 
Joined
Aug 13, 2011
Messages
200
Reaction score
7
Points
18
Location
West Sussex
I don't have the WeatherCat app myself, and so don't know about it's features.
But I'm assuming that the "ExternalTemp" command returns an AppleScript real number data type.
Is that correct ?

If indeed the WeatherCat app is returning a real number, then you have to modify the real number to the decimal places you want, before passing it to the "say" AppleScript command.
If you need a method for rounding AppleScript real decimal numbers, then I will post a simple method for this if that is what you require.

Your repeat loop does not appear to have an end, and will run until you quit the Script.
Was that your intention ?

I would also consider splitting your AppleScript code into separate methods, in order to make the code more readable and extendable.
Perhaps consider one method for retreiving the ExternalTemp, and another for rounding the returned real number, and another for speaking the results.

Regards Mark
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top