11-24-2015, 12:39 PM #1
- Member Since
- Nov 24, 2015
Applescript that speaks the temperature
- Rep Power
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
set currentTemperature to ExternalTemp
if oldCurrentTemperature is not currentTemperature then
tell current application
say "Current temperature is"
say currentTemperature as string
set oldCurrentTemperature to currentTemperature
- 11-28-2015, 04:46 PM #2
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.
11-29-2015, 12:02 AM #3
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
By GratefulDean in forum macOS - Operating SystemReplies: 4Last Post: 09-27-2012, 03:11 PM
By OneMoreThing... in forum Apple Rumors and ReportsReplies: 0Last Post: 05-16-2011, 10:32 AM
By Tanner31593 in forum macOS - Operating SystemReplies: 12Last Post: 01-14-2008, 06:58 PM
By oo5yolo10 in forum Buy/Sell/TradeReplies: 8Last Post: 03-03-2005, 03:00 PM
By schweb in forum Apple Rumors and ReportsReplies: 2Last Post: 04-17-2003, 03:38 PM