It is currently March 29th, 2024, 8:48 am

How to change color of Script Output?

Get help with creating, editing & fixing problems with skins
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: How to change color of Script Output?

Post by jsmorley »

Bugmenot wrote:Iam pretty sure 3 is below 10. But to be really sure i have also tried setting the ifabovevalue to 9 and its still stays white.
3 Is also below 9... ;-)

This simple code should demonstrate the logic.

Code: Select all

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

[Variables]

[MeasureOne]
Measure=Loop
StartValue=0
EndValue=10
IfBelowValue=6
IfBelowAction=[!SetOption MeterOne FontColor "247,120,111,255"]
IfAboveValue=5
IfAboveAction=[!SetOption MeterOne FontColor "129,247,111,255"]

[MeterOne]
Meter=String
FontSize=11
FontWeight=400
FontColor=129,247,111,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=Hello World
When the value is 0, 1, 2, 3, 4, or 5 is will be "below 6" and will be red. When the value is 6, 7, 8, 9 or 10 it will be "above 5" and will be green.
Bugmenot
Posts: 25
Joined: October 7th, 2016, 9:38 am

Re: How to change color of Script Output?

Post by Bugmenot »

Haha, i do understand the logic :D

But i dont understand why its not working. I got the .ps1 script which returns the value 3. But the color does not change no matter what number i set in the .ps1 script. Iam restarting after every change.
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: How to change color of Script Output?

Post by jsmorley »

Bugmenot wrote:Haha, i do understand the logic :D

But i dont understand why its not working. I got the .ps1 script which returns the value 3. But the color does not change no matter what number i set in the .ps1 script. Iam restarting after every change.
I would set up a temporary meter like this:

[MeterTest]
Meter=String
FontSize=11
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=Text valuue is: XX[MeasureRun]XX#CRLF#Number value is: [MeasureRun:]
DynamicVariables=1

That way we can see what the actual string value is that the measure is returning. The "XX" on the front and back is to detect if there are maybe some leading or trailing spaces or carriage return / linefeed characters that are not allowing Rainmeter to see the string returned as a valid "number".

That will display what the actual string value is, and also what the "number" value that Rainmeter is getting is.
Bugmenot
Posts: 25
Joined: October 7th, 2016, 9:38 am

Re: How to change color of Script Output?

Post by Bugmenot »

It says 3, could be nothing else, because there is nothing else in the .ps1 file^^
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: How to change color of Script Output?

Post by jsmorley »

Bugmenot wrote:It says 3, could be nothing else, because there is nothing else in the .ps1 file^^
The contents of the .ps1 file has nothing to do with it. It is what running the .ps1 file outputs to standard out in a powershell environment that matters.
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: How to change color of Script Output?

Post by balala »

Bugmenot wrote:Haha, i do understand the logic :D

But i dont understand why its not working. I got the .ps1 script which returns the value 3. But the color does not change no matter what number i set in the .ps1 script. Iam restarting after every change.
Maybe you should take into account to switch to the IfConditions, instead of the IfActions. I'd be tempted to replace the IfActions, with the following options:

Code: Select all

IfCondition=([MeasureRun]<10)
IfTrueAction=[!SetOption MeterResult FontColor "255,255,255,255"]
IfFalseAction=[!SetOption MeterResult FontColor "0,0,0,255"]
DynamicVariables=1
Note the most important things here: the ([MeasureRun]<10) condition and the DynamicVariables=1 options.

On the other hand, in the original Ifactions, you still didn't include the value 10 nowhere. IfBelowValue=10 means the values up to 9 (to be below 10), while IfAboveAction=10 means the values above 10 (11, 12 and so on). Where should be included the value 10?
You probably will have to modify either the IfBelowValue, either the AfAboveValue. Something like:

Code: Select all

IfAboveValue=9
IfAboveAction=[!SetOption MeterResult FontColor "0,0,0,0"]
IfBelowValue=10
IfBelowAction=[!SetOption MeterResult FontColor "255,255,255,255"]
which means the value 10 is included into to the IfAboveValue (obviously probably here you'll have to modify the value 10).
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: How to change color of Script Output?

Post by jsmorley »

Code: Select all

[MeasureRun]
Measure=Plugin
Plugin=RunCommand
Parameter=powershell -NoLogo #@#Scripts\passwordExpires.ps1
State=Hide
OutputType=ANSI
OutputFile=#CURRENTPATH#output.txt
Use that OutputFile option on your measure, and then zip up and attach output.txt to a response here. I don't want you to copy and paste it here, I want the file. I want it zipped up, so I have the actual, physical file to look at.
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: How to change color of Script Output?

Post by jsmorley »

While IfCondition is probably a better choice (always is), I don't think that, or the logic flaw that leaves one number out of the consideration, is the root of this issue.
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: How to change color of Script Output?

Post by balala »

jsmorley wrote:While IfCondition is probably a better choice (always is), I don't think that, or the logic flaw that leaves one number out of the consideration, is the root of this issue.
Certainly not! It was just an observation. My thought was that, as I wrote above, the IfCondition, with the condition written in the ([MeasureRun]<10) form, could help. But let's see the file, as you asked.
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: How to change color of Script Output?

Post by jsmorley »

I see the issue. RunCommand is designed to return both a string value (the output of the command to Standard Out) and a number value (the errorlevel of the command execution). If you use the number value of any command that succeeds, it will always be "1".

So the issue is here:

Code: Select all

[MeasureRun]
Measure=Plugin
Plugin=RunCommand
Parameter=powershell -NoLogo #@#Scripts\passwordExpires.ps1
State=Hide
OutputType=ANSI
IfAboveValue=5
IfAboveAction=[!SetOption MeterResult FontColor 255,0,0,255]
IfBelowValue=6
IfBelowAction=[!SetOption MeterResult FontColor 0,255,0,255]
What is going on is that the IfActon options are by design always going to use the "number" value of the measure they are attached to. In this case, that will always be "1".

So the long and the short of it is that you were on to it all the time balala... ;-)

If you use IfCondition instead, where you have more control over what is evaluated, you can ask it to test the "string" value of the measure and treat it as a "number", rather than using the actual "number" value, which will again always be "1" if the command succeeds.

Code: Select all

[MeasureRun]
Measure=Plugin
Plugin=RunCommand
Parameter=powershell -NoLogo #@#Scripts\passwordExpires.ps1
State=Hide
OutputType=ANSI
IfCondition=[MeasureRun] < 6
IfTrueAction=[!SetOption MeterResult FontColor "247,234,82,255"]
IfFalseAction=[!SetOption MeterResult FontColor "82,247,109,255"]
DynamicVariables=1
That will work...

https://docs.rainmeter.net/manual-beta/plugins/runcommand/
The string value of the measure

The string value of the measure will be any output that the program writes to STDOUT. In effect, what you would see if you manually ran the command in a cmd.exe Command Prompt window will become the string value of the measure.

The number value of the measure

The number value of the measure will indicate if the command finished with or without any errors. You can get the number value of the measure by using Section Variables (e.g. [MeasureName:]). Before the command has first run, the number value of the measure will be -1. While the command is running, the number value of the measure will be 0. If an error occurs, the number value of the measure will indicate the type of error that has occurred. If the program finishes without error, the number value of the measure will be 1, meaning "success". These can be used to take different skin actions depending on the numeric return value.