IfConditions


IfCondition options are used in any measure, of any type, to evaluate a mathematical formula. The formula will be evaluated as "true" or "false", and will execute IfTrueAction or IfFalseAction action options, which will contain one or more Bangs or commands.

Note: IfCondition can only be used to evaluate a numeric mathematical formula. No string values may be used in the condition test. See IfMatchActions to test and take action on string values.

The formula uses the same syntax as described on the Formulas page but does not need to be surrounded in parenthesis. Like the Calc measure, measure names do not need [brackets] and are always dynamic when referenced inside the IfCondition.

There can be multiple sets of condition and action options in the measure, by using IfCondition2 / IfTrueAction2 / IfFalseAction2 and so on.

IfConditions are similar in functionality to IfActions, with a few important and powerful differences.

  • The formula is not based on the value of the measure the IfCondition is in, but can reference any measures, variables or section variables.
  • There can be an IfTrueAction, IfFalseAction or both for each IfCondition, so you can take appropriate actions not only when the result is "true", but also when it is "false".
  • The syntax allows for a single IfCondition to embed logical AND && and OR || comparisons in the formula. Unlike IfEqualValue for instance, which allows for a single comparison, you could use IfCondition=(MeasureName = 5) || (MeasureName = 10), to check if the value of MeasureName is "5" OR "10". You can also use the full range of logical operators, so rather than being limited to "equal", "above" or "below", you can use any of <> = < > <= >= && ||.

Options

IfCondition, IfCondition2, ..., IfConditionN

A mathematical formula, which when evaluated will result in "true" or "false".

Examples:

IfCondition=MeasureName >= 10

IfCondition=MeasureOne = (MeasureTwo + #VarName#) / 2

IfCondition=(MeasureName > 5) && (MeasureName < 10)

IfCondition=(MeasureName = 25) || (MeasureName = 50) || (MeasureName = 75)

Note: The comparison on either side of logical AND && and OR || operators must be enclosed in (parentheses).

IfTrueAction, IfTrueAction2, ..., IfTrueActionN

Optional action to be executed when the formula expressed in IfCondition results in "true". The action is executed only once when the condition becomes "true", so it needs to become "false" and again "true" to execute again.

IfFalseAction, IfFalseAction2, ..., IfFalseActionN

Optional action to be executed when the formula expressed in IfCondition results in "false". The action is executed only once when the condition becomes "false", so it needs to become "true" and again "false" to execute again.

IfConditionMode Default: 0

If set to 1, the evaluation of the condition will execute the appropriate actions in IfTrueAction or IfFalseAction on every update of the measure.

Note: Care should be taken not to create an infinite loop in the actions. In particular, !Refresh, !Update and !UpdateMeasure #CURRENTSECTION# should generally be avoided when IfConditionMode=1.

Example

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

[MeasureCPU]
Measure=CPU
IfCondition=MeasureCPU < 10
IfTrueAction=[!SetOption MeterCPU Text "CPU usage is less than 10 percent"]
IfCondition2=(MeasureCPU >= 10) && (MeasureCPU <= 90)
IfTrueAction2=[!SetOption MeterCPU Text "CPU usage is between 10 and 90 percent"]
IfCondition3=MeasureCPU > 90
IfTrueAction3=[!SetOption MeterCPU Text "CPU usage is more than 90 percent!"]
OnUpdateAction=[!UpdateMeter MeterCPU][!Redraw]

[MeterCPU]
Meter=String
FontSize=12
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1