It is currently April 27th, 2024, 7:38 pm

Change the color of a text according to a date

Get help with creating, editing & fixing problems with skins
SeubZero
Posts: 4
Joined: April 11th, 2020, 4:07 pm

Change the color of a text according to a date

Post by SeubZero »

Hello everyone and sorry for my English.
I'm looking to change the color of text based on the last modification date of a file.

For this I use Jeffrey Morley's module, LuaTextFile2.0
The module simply reads the contents of a TXT file.

I would like to change the text color based on the last modification date of a specific file.

I try to adapt the module but it doesn't work, maybe the problem is Meter Display

Thank you all for your help.

Sincerely,

Code: Select all

[Rainmeter]
Author=Jeffrey Morley
Update=1000
DynamicWindowSize=1

[MeasureFile]
Measure=Plugin
Plugin=FileView
Path=C:\test.txt
Type=DateModified
Format="%Y-%m-%d"

[MeasureTime]
Measure=Time
Format=%Y-%m-%d

[MeasureLuaScript]
Measure=Script
ScriptFile="#CURRENTPATH#LuaTextFile.lua"
FileToRead=C:\Journal.txt

[MeterDisplay]
Meter=String
MeasureName=MeasureLuaScript
W=300
H=500
FontFace=Segoe UI
FontSize=11
FontColor=255,255,255,255
SolidColor=0,0,0,1
AntiAlias=1
ClipString=1
Text=[&MeasureLuaScript]

; Condition pour changer la couleur du texte si la date de modification est inférieure à la date d'aujourd'hui
DynamicVariables=1
IfCondition=(MeasureFile < MeasureTime)
IfTrueAction=[!SetOption MeterDisplay FontColor "255,0,0,255"]

User avatar
Yincognito
Rainmeter Sage
Posts: 7178
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Change the color of a text according to a date

Post by Yincognito »

I can't answer this in detail now (maybe tomorrow), but there are multiple problems with your code:
- FileView parent measures only take folders as the value of their Path option, not files
- because of the above, a FileView child measure getting the last modified date of the file corresponding to a certain Index would be needed
- even so, since the Index option is a positional and not a name value of a file or folder from Path, you'd need to use the WildcardSearch option to specify your file in the parent FileView measure
- the options you used to get the last modified date in the FileView measure are wrong, see the Rainmeter manual for the FileView plugin
- once you get that date, you need to pass it to a Time measure having the proper TimeStampFormat option, see the manual for the Time measure
- once you have the Time measure, you'll need to use [YourTimeMeasure:Timestamp] to be able to compare it with some other Time measure's :Timestamp
- IfConditions are only used in measures, not meters
- DynamicVariables=1 might be needed in certain sections from the code

The needed changes are not particularly complicated, but they involve a few more steps to get what you want. Oh, and for the record, Lua is not absolutely needed to read a file, a WebParser measure having its URL option set to a local file can do it too (just saying, I guess that part is the only one working in your code already).
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
SilverAzide
Rainmeter Sage
Posts: 2613
Joined: March 23rd, 2015, 5:26 pm

Re: Change the color of a text according to a date

Post by SilverAzide »

MeasureFile is returning a string, and MeasureTime is returning a timestamp (a number). So your comparsion IfCondition=(MeasureFile < MeasureTime) can't work.

You can convert the MeasureTime string to a "real" time using another Time measure. Once you do that, you can compare the two resulting timestamps and it should work.
Gadgets Wiki GitHub More Gadgets...
User avatar
eclectic-tech
Rainmeter Sage
Posts: 5407
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: Change the color of a text according to a date

Post by eclectic-tech »

SeubZero wrote: February 15th, 2024, 10:51 pm Hello everyone and sorry for my English.
I'm looking to change the color of text based on the last modification date of a file.

For this I use Jeffrey Morley's module, LuaTextFile2.0
The module simply reads the contents of a TXT file.

I would like to change the text color based on the last modification date of a specific file.

I try to adapt the module but it doesn't work, maybe the problem is Meter Display

Thank you all for your help.

Sincerely,
You are close to the answer...

Let's start by creating a new variable 'SearchFile' and set it's value to 'test.txt'

Code: Select all

[Variables]
SearchFile=test.txt
Now create a FileView parent measure that will search for that filename and return all the file information if found.

Code: Select all

; Reads the 'Path' and contains one file information, if 'SearchFile' is found
[MeasureFile]
Measure=Plugin
Plugin=FileView
Path="C:\Temp"
ShowDotDot=0
ShowFolder=0
Count=1
WildcardSearch=#SearchFile#
To tell if the parent measure found a file, add a FileView measure that shows the FileCount value of the parent measure

Code: Select all

[MeasureFileCount]
Measure=Plugin
Plugin=FileView
Path=[MeasureFile]
Type=FileCount
You can see this in the Rainmeter log (!About)) and should look like this:
timelog.jpg
Now we know if the SearchFile was found and can get the DateModified in a FileView Child measure

Code: Select all

[MeasureFileDate]
Measure=Plugin
Plugin=FileView
Path=[MeasureFile]
Index=1
Type=FileDate
DateType=Modified
Next, we need to know the current time, compare it to MeasureFileDate, and change the fontcolor
If the file is not found, the NUMBER value of [MeasureFileDate] will be zero
Note: IfConditions will ALWAYS use the NUMBER value of the measures, so the Timestamp values are used to compare the dates

Code: Select all

[MeasureTime]
Measure=Time
IfCondition=(MeasureFileDate < MeasureTime)&&(MeasureFileDate <> 0)
IfTrueAction=[!SetOption MeterDisplay FontColor "255,0,0,255"][!UpdateMeter MeterDisplay][!Redraw]
All that is needed is to display the information

Code: Select all

[MeterDisplay]
Meter=String
MeasureName=MeasureFileDate
W=300
H=500
FontFace=Segoe UI
FontSize=11
FontColor=255,255,255,255
SolidColor=0,0,0,1
AntiAlias=1
ClipString=1
Text=FILE: #SearchFile##CRLF#MODIFIED: %1

; Condition pour changer la couleur du texte si la date de modification est inférieure à la date d'aujourd'hui
; DynamicVariables=1
That corrects the measures in your code.
Let us know if you have any questions.

Code: Select all

[Rainmeter]
Author=Jeffrey Morley
Update=1000
DynamicWindowSize=1

[Variables]
SearchFile=text.txt

; Reads the 'Path' and contains one file information, if 'SearchFile' is found
[MeasureFile]
Measure=Plugin
Plugin=FileView
Path="C:\Temp"
ShowDotDot=0
ShowFolder=0
Count=1
WildcardSearch=#SearchFile#

; Added only for information
; Show the number of files found in the parent measure, in the log
[MeasureFileCount]
Measure=Plugin
Plugin=FileView
Path=[MeasureFile]
Type=FileCount

[MeasureFileDate]
Measure=Plugin
Plugin=FileView
Path=[MeasureFile]
Index=1
Type=FileDate
DateType=Modified

[MeasureTime]
Measure=Time
IfCondition=(MeasureFileDate < MeasureTime)&&(MeasureFileDate <> 0)
IfTrueAction=[!SetOption MeterDisplay FontColor "255,0,0,255"][!UpdateMeter MeterDisplay][!Redraw]

[MeterDisplay]
Meter=String
MeasureName=MeasureFileDate
W=300
H=500
FontFace=Segoe UI
FontSize=11
FontColor=255,255,255,255
SolidColor=0,0,0,1
AntiAlias=1
ClipString=1
Text=FILE: #SearchFile##CRLF#MODIFIED: %1

; Condition pour changer la couleur du texte si la date de modification est inférieure à la date d'aujourd'hui
; DynamicVariables=1
NOTE:
With the current IfCondition test in [MeasureTime] every file will be older than the current time. To test for older modified dates, all you need to do is to subtract the number of daily seconds (86400) from the MeasureTime in the IfCondition test.

E.g. To test for files modified more than 3 days ago use this IfCondition:
IfCondition=(MeasureFileDate < (MeasureTime - (86400 * 3)))&&(MeasureFileDate <> 0)
You do not have the required permissions to view the files attached to this post.
SeubZero
Posts: 4
Joined: April 11th, 2020, 4:07 pm

Re: Change the color of a text according to a date

Post by SeubZero »

Hello, thank you for your many feedbacks and the patience you had to help me, it works perfectly.
User avatar
eclectic-tech
Rainmeter Sage
Posts: 5407
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: Change the color of a text according to a date

Post by eclectic-tech »

Happy to help.