It is currently March 28th, 2024, 11:59 am

How to run a 'runCommand' at a regular interval?

Get help with installing and using Rainmeter.
Post Reply
jn_meter
Posts: 136
Joined: December 27th, 2016, 12:04 pm

How to run a 'runCommand' at a regular interval?

Post by jn_meter »

Dear all

I've some Rainmeter experience but I am baffled in trying to do something simple, namely, run a RunCommand at an inverval. I can't simply put the command in a measure and create a corresponding meter, because RunCommands run only when called by . .!RunCommand. I've looked at the documentation on 'timers' but I don't understand it (largely because that documentation did not seem to contain anything on . . the interval at which the timed action runs at!).

Here's the code I want to run at an interval (and that code, so far as it goes, works).

Code: Select all

[measure_command_checkWindowsFirewall]
Measure=Plugin
Plugin=RunCommand
Parameter=netsh advfirewall show private state
OutputType=ANSI
;OutputFile=%TEMP%\FW
State=Hide
; Disabled=1
Timeout=400
IfMatch=.*ON.*
IfNotMatchAction=[!SetOption meter_WindowsFirewall FontColor #red#] [!SetOption meter_WindowsFirewall Text "No firewall"] [!Redraw]
IfMatchAction=[!SetOption meter_WindowsFirewall FontColor #darkGreen#] [!SetOption meter_WindowsFirewall Text "Firewall OK"] [!Redraw]
I'd really appreciate it anyone can shed light. Thanks.
User avatar
balala
Rainmeter Sage
Posts: 16109
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: How to run a 'runCommand' at a regular interval?

Post by balala »

There are more possibilities:
  • Add the following option to the [Rainmeter] section of your skin: OnUpdateAction=[!CommandMeasure "measure_command_checkWindowsFirewall" "Run"]. On each update cycle, the above OnUpdateAction option is executed, so the RunCommand plugin will be ran regularly.
  • If you want to run the measure rarer, you could add the following calc measure:

    Code: Select all

    [SomeMeasure]
    Measure=Calc
    Formula=1
    OnUpdateAction=[!CommandMeasure "measure_command_checkWindowsFirewall" "Run"]
    UpdateDivider=2
    Again, the [measure_command_checkWindowsFirewall] measure will run every time the [SomeMeasure] measure is updated. Due to the UpdateDivider, this will happen less often than the update of the skin.
  • The same way, you could add a similar option to any existing measure or meter of the skin, to not introduce a new one.
jn_meter
Posts: 136
Joined: December 27th, 2016, 12:04 pm

Re: How to run a 'runCommand' at a regular interval?

Post by jn_meter »

balala,

That's very helpful. Thank you. I've implemented the longer, less-frequent-update version and it works. I did try that before, except I'd omitted the 'formula=1' (the addition of which doesn't seem intuitive!).

However, a small problem remains. To wit: when the skin first runs, it displays 'No firewall' briefly, before switching to 'Firewall OK'. I wonder why this is? Is the initial check returning the 'no firewall' result? If so, why? If not, why do I see the 'no firewall' text?
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: How to run a 'runCommand' at a regular interval?

Post by jsmorley »

jn_meter wrote:balala,

That's very helpful. Thank you. I've implemented the longer, less-frequent-update version and it works. I did try that before, except I'd omitted the 'formula=1' (the addition of which doesn't seem intuitive!).

However, a small problem remains. To wit: when the skin first runs, it displays 'No firewall' briefly, before switching to 'Firewall OK'. I wonder why this is? Is the initial check returning the 'no firewall' result? If so, why? If not, why do I see the 'no firewall' text?
The problem is that when the skin is first loaded or when refreshed the "threaded" RunCommand plugin measure has not yet run / finished the first time, and so the value of the measure is "" or "0".

In [Rainmeter] put:

OnRefreshAction=[!CommandMeasure "measure_command_checkWindowsFirewall" "Run"][!UpateMeasure "measure_command_checkWindowsFirewall"][!UpdateMeter "*"][!Redraw]

Then also leave your measure that is running the command on a regular, timed basis. What this will do is ensure that the measure has a value at the end of the very first update cycle, and that meters dependent on it are updated right away.

See if this kick in the pants doesn't correct it for you.
jn_meter
Posts: 136
Joined: December 27th, 2016, 12:04 pm

Re: How to run a 'runCommand' at a regular interval?

Post by jn_meter »

The 'kick in the pants' failed, unfortunately! For, it remains the case that, when the script starts, and the firewall is on, briefly I see the text 'no firewall'. I tried messing around with having the measure - the timed one that calls the runCommand - initially disabled, and then getting something to enable it, but that didn't work either.
jn_meter
Posts: 136
Joined: December 27th, 2016, 12:04 pm

Re: How to run a 'runCommand' at a regular interval?

Post by jn_meter »

I think the problem might have to do with the 'ifmatch' evaluating too early (as is discussed on this page) but I am having trouble working around that.
Post Reply