It is currently April 18th, 2024, 2:16 am

How to change colour on hardrive freediskpace

Get help with installing and using Rainmeter.
Godsgrave
Posts: 3
Joined: January 17th, 2021, 8:37 pm

How to change colour on hardrive freediskpace

Post by Godsgrave »

I'm trying to customize my desktop (who is not lol) and trying to edit some skins which I already like. Currently, I have several skins active and one of them is showing the disk space in use on all drives. Currently, It is showing the percentage inverted (I want that). What I want to have is that the colour is changing on a X percentage. Lets say on <=74 its white, >=75 its orange and on anything above 90 its red. Is this possible in rainmeter, if yes how can I do it?

While I did some googling I was not able to find something that worked. So that is why I'm posting the question here.

The unedited code that I use for the drives.

Code: Select all

[MeasureHDInverse]
Measure=FreeDiskSpace
Drive=#Drive#:
InvertMeasure=1

----------------------------------
HDD METER

[MeterPercent]
Meter=STRING
MeasureName=MeasureHDInverse
X=155
Y=6
FontColor=255,255,255,255
FontSize=12
FontFace=Roboto-Bold
AntiAlias=1
Text="%1%"
Percentual=1
AutoScale=1
I tried to add this to MeasureHDInverse, but the colour is always red.

Code: Select all

IfAboveValue=75
IfAboveAction=[!SetOption MeterPercent FontColor 255,0,0,255]
IfAboveValue=90
IfBelowAction=[!SetOption MeterPercent FontColor 255,165,0,255]
IfBelowValue=75
IfBelowAction=[!SetOption MeterPercent FontColor 255,255,255,255]
I also tried to add this to MeterPercent, but now its green. Not sure why, since I don't have green code.

Code: Select all

FontColor=%1% => 75 ? 255,165,0,255 : 255,255,255,255
FontColor=%1% => 90 ? 255,0,0,255 : 255,255,255,255
User avatar
ikarus1969
Posts: 571
Joined: February 28th, 2011, 3:20 pm
Location: Vienna, Austria

Re: How to change colour on hardrive freediskpace

Post by ikarus1969 »

Godsgrave wrote: January 17th, 2021, 9:25 pm I tried to add this to MeasureHDInverse, but the colour is always red.

Code: Select all

IfAboveValue=75
IfAboveAction=[!SetOption MeterPercent FontColor 255,0,0,255]
IfAboveValue=90
IfBelowAction=[!SetOption MeterPercent FontColor 255,165,0,255]
IfBelowValue=75
IfBelowAction=[!SetOption MeterPercent FontColor 255,255,255,255]
From the IfAbove/IfEqual/IfBelow you always can have only one. You can read this in the documentation: https://docs.rainmeter.net/manual-beta/measures/general-options/ifactions/
Godsgrave wrote: January 17th, 2021, 9:25 pmI also tried to add this to MeterPercent, but now its green. Not sure why, since I don't have green code.

Code: Select all

FontColor=%1% => 75 ? 255,165,0,255 : 255,255,255,255
FontColor=%1% => 90 ? 255,0,0,255 : 255,255,255,255
On meters you can't use the %1 to compare things - and not more than once as you did. Instead I would recommend using the IfCondition on the measure. Something like that would work - i assume you have a measure MeasureHDTotal that gives you the total of used disc space:

Code: Select all

[MeasureHDTotal]
Measure=FreeDiskSpace
Drive=#Drive#:
Total=1

[Measure_HD_Used_Percentage]
Measure=CALC
Formula=100 * (MeasureHDInverse / MeasureHDTotal)
IfCondition=Measure_HD_Used_Percentage <= 75
IfTrueAction=[!SetOption MeterPercent FontColor 255,255,255,255][!UpdateMeter MeterPercent][!Redraw]
IfCondition2=((Measure_HD_Used_Percentage > 75) && (Measure_HD_Used_Percentage < 90)
IfTrueAction2=[!SetOption MeterPercent FontColor 255,165,0,255][!UpdateMeter MeterPercent][!Redraw]
IfCondition3=Measure_HD_Used_Percentage >= 90
IfTrueAction3=[!SetOption MeterPercent FontColor 255,0,0,255][!UpdateMeter MeterPercent][!Redraw]
Godsgrave
Posts: 3
Joined: January 17th, 2021, 8:37 pm

Re: How to change colour on hardrive freediskpace

Post by Godsgrave »

ikarus1969 wrote: January 18th, 2021, 7:03 am I assume you have a measure MeasureHDTotal that gives you the total of used disc space
No I did not have that. I have the following:

Code: Select all

[Rainmeter]
Update=1000

[Variables]
Drive=C:

[MeasureHDInverse]
Measure=FreeDiskSpace
Drive=#Drive#
InvertMeasure=1

[MeterPercent]
Meter=STRING
MeasureName=MeasureHDInverse
X=155
Y=6
FontColor=255,255,255,255
FontSize=12
FontFace=Roboto-Bold
AntiAlias=1
Text="%1%"
Percentual=1
AutoScale=1

[MeterHDDStatus]
Meter=STRING
Text="HDD #Drive#"
X=7
Y=6
FontColor=255,255,255,255
FontSize=12
FontFace=Roboto-Bold
AntiAlias=1

[MeterBar]
MeasureName=MeasureHDInverse
Meter=BAR
X=10
Y=25
W=180
H=5
BarOrientation=HORIZONTAL
BarColor=255,255,255,255

[BarLine]
Meter=IMAGE
X=10
Y=30
W=180
H=5
SolidColor=255,255,255,50
I did add your code, When testing it will only show the percentage in white. Changing the IfConditions to something else (lets say 75 -> 10) will have no effect on the colour. Even if the disk is 47% used.
ikarus1969 wrote: January 18th, 2021, 7:03 am
On meters you can't use the %1 to compare things - and not more than once as you did. Instead I would recommend using the IfCondition on the measure. Something like that would work - i assume you have a measure MeasureHDTotal that gives you the total of used disc space:

Code: Select all

[MeasureHDTotal]
Measure=FreeDiskSpace
Drive=#Drive#:
Total=1

[Measure_HD_Used_Percentage]
Measure=CALC
Formula=100 * (MeasureHDInverse / MeasureHDTotal)
IfCondition=Measure_HD_Used_Percentage <= 75
IfTrueAction=[!SetOption MeterPercent FontColor 255,255,255,255][!UpdateMeter MeterPercent][!Redraw]
IfCondition2=((Measure_HD_Used_Percentage > 75) && (Measure_HD_Used_Percentage < 90)
IfTrueAction2=[!SetOption MeterPercent FontColor 255,165,0,255][!UpdateMeter MeterPercent][!Redraw]
IfCondition3=Measure_HD_Used_Percentage >= 90
IfTrueAction3=[!SetOption MeterPercent FontColor 255,0,0,255][!UpdateMeter MeterPercent][!Redraw]
User avatar
ikarus1969
Posts: 571
Joined: February 28th, 2011, 3:20 pm
Location: Vienna, Austria

Re: How to change colour on hardrive freediskpace

Post by ikarus1969 »

Godsgrave wrote: January 18th, 2021, 3:46 pm I did add your code, When testing it will only show the percentage in white. Changing the IfConditions to something else (lets say 75 -> 10) will have no effect on the colour. Even if the disk is 47% used.
There was an error in my code, but that's not the reason why the percentage is in white. The reason for this is the IfBelowValue=75 and IfBelowAction... you posted in your first posting. So i thought you want white as the color when the percentage is below 75%.

Nevertheless, i corrected my code and integrazed it it in yours. Now the percentage text is green (a font-color of 0,255,0,255).
Unbenannt.PNG

Code: Select all

[Rainmeter]
Update=1000

[Variables]
Drive=C:

[MeasureHDInverse]
Measure=FreeDiskSpace
Drive=#Drive#
InvertMeasure=1

[MeasureHDTotal]
Measure=FreeDiskSpace
Drive=#Drive#
Total=1

[Measure_HD_Used_Percentage]
Measure=CALC
Formula=100 * (MeasureHDInverse / MeasureHDTotal)
IfCondition=Measure_HD_Used_Percentage <= 75
IfTrueAction=[!SetOption MeterPercent FontColor 0,255,0,255][!UpdateMeter MeterPercent][!Redraw]
IfCondition2=((Measure_HD_Used_Percentage > 75) && (Measure_HD_Used_Percentage < 90))
IfTrueAction2=[!SetOption MeterPercent FontColor 255,165,0,255][!UpdateMeter MeterPercent][!Redraw]
IfCondition3=Measure_HD_Used_Percentage >= 90
IfTrueAction3=[!SetOption MeterPercent FontColor 255,0,0,255][!UpdateMeter MeterPercent][!Redraw]

[MeterPercent]
Meter=STRING
MeasureName=MeasureHDInverse
X=155
Y=6
FontColor=255,255,255,255
FontSize=12
FontFace=Roboto-Bold
AntiAlias=1
Text="%1%"
Percentual=1
AutoScale=1

[MeterHDDStatus]
Meter=STRING
Text="HDD #Drive#"
X=7
Y=6
FontColor=255,255,255,255
FontSize=12
FontFace=Roboto-Bold
AntiAlias=1

[MeterBar]
MeasureName=MeasureHDInverse
Meter=BAR
X=10
Y=25
W=180
H=5
BarOrientation=HORIZONTAL
BarColor=255,255,255,255

[BarLine]
Meter=IMAGE
X=10
Y=30
W=180
H=5
SolidColor=255,255,255,50
You do not have the required permissions to view the files attached to this post.
User avatar
balala
Rainmeter Sage
Posts: 16143
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: How to change colour on hardrive freediskpace

Post by balala »

I'd add something here, which has not been explained.
In the initial code, posted by Godsgrave, the [MeasureHDInverse] measure returns the amount of used space, not as a percentage (this is important), but in bytes. So you can't compare this with 75, 90 or whatever percent, makes no sense.
Why in this case the [MeterPercent] meter shows a percentage, not the value returned by the measure? Due to the Percentual=1 option, added to this meter, which makes the meter to show the value as a percent, 100% representing the entire disk space. If you remove temporary this option, can see what am I talking about.
ikarus1969 wrote: January 18th, 2021, 6:16 pm Nevertheless, i corrected my code and integrazed it it in yours.
A little improvement I'd add to ikarus1969's solution is the following: would replace his Formula with this: Formula=100 * (MeasureHDInverse / ( MeasureHDTotal + 0.0001 )). As you can see I added an extremely small value to the denominator and did this because this doesn't change the percentage, but if the disk used into the skin doesn't exist (for instance a not connected removable drive), with ikarus1969's original formula you get an error in the log when refreshing the skin, a Division by 0 message. This is completely normal, because both the denominator and the numerator are zero. The numerator doesn't cause a problem, but as you probably know, the denominator can't be zero (you can't divide by zero). By adding that small value to the denominator, this error message is avoided.
ikarus1969 wrote: January 18th, 2021, 6:16 pm So i thought you want white as the color when the percentage is below 75%.
But exactly this was asked:
Godsgrave wrote: January 17th, 2021, 9:25 pm Lets say on <=74 its white, >=75 its orange and on anything above 90 its red.
Godsgrave
Posts: 3
Joined: January 17th, 2021, 8:37 pm

Re: How to change colour on hardrive freediskpace

Post by Godsgrave »

ikarus1969 wrote: January 18th, 2021, 6:16 pm You posted in your first posting. So i thought you want white as the color when the percentage is below 75%.
My apologies, maybe I wasn't clear. I want it indeed to change colour from white (standard colour) to orange when its above 75% and change it to red when its above 90%. When testing your earlier code I changed the statements to this to test if it works.

Code: Select all

IfCondition=Measure_HD_Used_Percentage <= 10
IfTrueAction=[!SetOption MeterPercent FontColor 255,255,255,255][!UpdateMeter MeterPercent][!Redraw]
IfCondition2=((Measure_HD_Used_Percentage > 10) && (Measure_HD_Used_Percentage < 30))
IfTrueAction2=[!SetOption MeterPercent FontColor 255,165,0,255][!UpdateMeter MeterPercent][!Redraw]
IfCondition3=Measure_HD_Used_Percentage >= 30
IfTrueAction3=[!SetOption MeterPercent FontColor 255,0,0,255][!UpdateMeter MeterPercent][!Redraw]
This is not the final if statement, just to test it our ;-).
ikarus1969 wrote: January 18th, 2021, 6:16 pm Nevertheless, i corrected my code and integrazed it it in yours
Thank you very much it works wonderfully! Just how I want it, minus the colour green :D. Simpel change, thank again!
balala wrote: January 18th, 2021, 7:02 pm I'd add something here, which has not been explained.
In the initial code, posted by Godsgrave, the [MeasureHDInverse] measure returns the amount of used space, not as a percentage (this is important), but in bytes. So you can't compare this with 75, 90 or whatever percent, makes no sense.
Why in this case the [MeterPercent] meter shows a percentage, not the value returned by the measure? Due to the Percentual=1 option, added to this meter, which makes the meter to show the value as a percent, 100% representing the entire disk space. If you remove temporary this option, can see what am I talking about.
Thank you for the wealth of information. Im very new to rainmeter, information like this is very helpful in understanding the issue and solving it the next time.
balala wrote: January 18th, 2021, 7:02 pm A little improvement I'd add to ikarus1969's solution is the following: would replace his Formula with this: Formula=100 * (MeasureHDInverse / ( MeasureHDTotal + 0.0001 )). As you can see I added an extremely small value to the denominator and did this because this doesn't change the percentage, but if the disk used into the skin doesn't exist (for instance a not connected removable drive), with ikarus1969's original formula you get an error in the log when refreshing the skin, a Division by 0 message. This is completely normal, because both the denominator and the numerator are zero. The numerator doesn't cause a problem, but as you probably know, the denominator can't be zero (you can't divide by zero). By adding that small value to the denominator, this error message is avoided.
Thank you for explain this too. I wouldn't have thought if it if you didn't say it.
User avatar
balala
Rainmeter Sage
Posts: 16143
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: How to change colour on hardrive freediskpace

Post by balala »

Godsgrave wrote: January 19th, 2021, 9:20 am Thank you for the wealth of information. Im very new to rainmeter, information like this is very helpful in understanding the issue and solving it the next time.

Thank you for explain this too. I wouldn't have thought if it if you didn't say it.
I'm glad if any of the offered information is helpful. Don't worry, if you keep working in Rainmeter, after a while you'll realize many things by yourself. :thumbup: