Dear Reinhard, X-Air, and WeatherCat scripters,
Well I'm still sore and it didn't help that I had to continue trimming our hedge of Oleanders this afternoon, but hopefully I can get back to your questions today.
Yes, indeed - but since I wasn't able to round it to at least 1 cm, how should I be able to round it to the nearest ? cm? Ahh I know, Edouard will point me into the right direction...
Well, I had to search the web for a solution myself, but it turns out to be extremely simple. The goal is to get a value to the nearest ? value. So first multiply by 2. Then round the result to the nearest whole integer. Then divide by 2 (of course as a floating point operation!) Here is a little AppleScript function that does the trick:
set snow_mm to 75.26
set snow_mm to roundToHalf(snow_mm)
on roundToHalf(numberToRound)
set numberToRound to (round (numberToRound * 2)) as real
return (numberToRound / 2)
end roundToHalf
Another thing that could be possible via AppleScript is to "set" the value to zero ( "0" ) every one minute after midnight? With this trick I can force the graph to begin at zero. Possible?
I see that you have already come up with an alternative, but in my AppleScripts I do this differently. There is a way to get AppleScript to return the number of seconds since midnight and that's what I've use. Here is a snippet that shows the basic idea:
set daySeconds to time of (current date) -- get number of seconds since midnight
if (daySeconds ≤ 60) then -- If midnight occurred less than a minute ago
set dailySnowfall to 0
end if
I took a look at your script. So I assume that you are putting all this AppleScript into one of WeatherCat's synthetic channels? This might be a bit risky because WeatherCat has to wait for the script to complete before it can do anything else in that particular thread. I don't remember exactly, but this might be the main thread. Stu would know for sure.
I have a similar situation for WeatherCat memory. I collect that memory data in an independent AppleScript that creates a tiny file with just memory used as a single number. The synthetic channel therefore only needs to read the number and can immediately move on. Perhaps you should ask Stu if what you are doing is safe. If it is a bit of a risk, I can explain how to move the processing of the data from the ultrasonic sensor out of the synthetic channel and just have a tiny bit of AppleScript that reads the snow level from a file.
Cheers, Edouard