Author Topic: AppleScript - Help needed ...  (Read 7058 times)

wurzelmac

  • Storm
  • *****
  • Posts: 1361
    • ITIROLPR2
    • Wetterstation Pr?graten am Gro?venediger
  • Station Details: Davis Vantage PRO2 Plus (24h fan aspirated, wireless) with UV/Solar | Weather Envoy Data Logger | Mac mini 2023 M2 8/256 | 1x Canon EOS 1300D | macOS Sonoma 14.2
Re: AppleScript - Help needed ...
« Reply #15 on: October 27, 2018, 08:30:02 AM »
Dear Edouard and scripters  [computer],

after taking some time to dive into AppleScript a bit deeper and using Dr. Google to look around a bit on the web i found the Introduction to AppleScript Language Guide and here is what I need.  :)
So the script I am running at the moment is working and doing what I want so far:

Code: [Select]
set msg to do shell script "/usr/local/bin/python2.7 /Users/reinhard/schnee_client.py"

set height to 2030 #height of sensor above ground

considering case
try
set x to msg as number
set x to height - x
#resetting to zero to avoid negative numbers
if x is less than 0 then
set x to 0
end if
set snow_cm to x
#converting from mm to cm
set snow_cm to snow_cm / 10
#rounding to nearest ? cm
set quantum to 0.5
set snow_cm to (round snow_cm / quantum) * quantum
set t to (time string of (current date))
#resetting to zero to force floating graphdraw beginning at 0
#but leaving gaugedraw with a true daily Hi Lo value till short before midnight
if t is greater than "23:59:00" and t is less than "23:59:59" then
set snow_cm to 0
end if
return snow_cm
end try
end considering
Reinhard


xairbusdriver

  • Storm
  • *****
  • Posts: 3126
    • EW7115 (E7115)
    • KTNGERMA20
    • Mid-South Weather
  • Station Details: Davis VP2 wireless + remote Anemometer/2014 Mac min - 10.15.7/WC 3.0.5
Re: AppleScript - Help needed ...
« Reply #16 on: October 27, 2018, 05:05:03 PM »
Sounds familiar... ;)
THERE ARE TWO TYPES OF COUNTRIES
Those that use metric = #1 Measurement system
And the United States = The Banana system


elagache

  • Global Moderator
  • Storm
  • *****
  • Posts: 6494
    • DW3835
    • KCAORIND10
    • Canebas Weather
  • Station Details: Davis Vantage Pro-2, Mac mini (2018), macOS 10.14.3, WeatherCat 3
Two answers (Re: AppleScript - Help needed ...)
« Reply #17 on: October 27, 2018, 10:21:17 PM »
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...  [bounce]

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:

Code: [Select]
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:

Code: [Select]
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

wurzelmac

  • Storm
  • *****
  • Posts: 1361
    • ITIROLPR2
    • Wetterstation Pr?graten am Gro?venediger
  • Station Details: Davis Vantage PRO2 Plus (24h fan aspirated, wireless) with UV/Solar | Weather Envoy Data Logger | Mac mini 2023 M2 8/256 | 1x Canon EOS 1300D | macOS Sonoma 14.2
Re: AppleScript - Help needed ...
« Reply #18 on: October 28, 2018, 06:01:22 AM »
Hello Edouard,

thanks for looking into my script and your thoughts about it - much appreciated!
Reinhard


wurzelmac

  • Storm
  • *****
  • Posts: 1361
    • ITIROLPR2
    • Wetterstation Pr?graten am Gro?venediger
  • Station Details: Davis Vantage PRO2 Plus (24h fan aspirated, wireless) with UV/Solar | Weather Envoy Data Logger | Mac mini 2023 M2 8/256 | 1x Canon EOS 1300D | macOS Sonoma 14.2
Re: AppleScript - Help needed ...
« Reply #19 on: October 28, 2018, 09:50:00 AM »
Reinhard


wurzelmac

  • Storm
  • *****
  • Posts: 1361
    • ITIROLPR2
    • Wetterstation Pr?graten am Gro?venediger
  • Station Details: Davis Vantage PRO2 Plus (24h fan aspirated, wireless) with UV/Solar | Weather Envoy Data Logger | Mac mini 2023 M2 8/256 | 1x Canon EOS 1300D | macOS Sonoma 14.2
Re: Two answers (Re: AppleScript - Help needed ...)
« Reply #20 on: November 26, 2018, 01:01:53 PM »
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.

Hi Edouard,
since executing the whole script in a synthetic channel (for almost a month now) I did not notice one single problem.  [bounce] Just want to let you know!
Cheers,
Reinhard


Blicj11

  • Storm
  • *****
  • Posts: 3941
    • EW3808
    • KUTHEBER6
    • Timber Lakes Weather
  • Station Details: Davis Vantage Pro2 Plus | WeatherLinkIP Data Logger | iMac (2019), 3.6 GHz Intel Core i9, 40 GB RAM, macOS Ventura 13.6 | Sharx SCNC2900 Webcam | WeatherCat 3.3 | Supportive Wife
Re: AppleScript - Help needed ...
« Reply #21 on: November 26, 2018, 06:19:43 PM »
I love it when this stuff works.
Blick


elagache

  • Global Moderator
  • Storm
  • *****
  • Posts: 6494
    • DW3835
    • KCAORIND10
    • Canebas Weather
  • Station Details: Davis Vantage Pro-2, Mac mini (2018), macOS 10.14.3, WeatherCat 3
Glad to hear it!! (Re: AppleScript - Help needed ...)
« Reply #22 on: November 27, 2018, 12:18:30 AM »
Dear Reinhard, Blick, and WeatherCat scripters,

since executing the whole script in a synthetic channel (for almost a month now) I did not notice one single problem.  [bounce] Just want to let you know!

Glad to hear it!   :)  Honestly I was a bit concerned!  :-\

Cheers, Edouard