It is currently October 7th, 2022, 10:13 am

SOLVED - Problem with IfMatch

Get help with creating, editing & fixing problems with skins
User avatar
sl23
Posts: 1038
Joined: February 17th, 2011, 7:45 pm
Location: a Galaxy S7 far far away

SOLVED - Problem with IfMatch

Post by sl23 »

OK first, I'm on my lunch break at work so I'll have to post full code later.

But, a quick description of the issue...

I wanted a simple clock which puts my work pc to sleep at end of the day. I copied from my other skins to create a clock with some mouse actions and four buttons to shutdown, restart, etc.

I tried adding an IfCondition to the time measure, which didn't work. So used an If Match instead which worked on my home pc. But seems to put the work pc to sleep every 5mins!

I used this code:
IfMatch=4.25 (to turn off at that time.)
IfMatchAction=#Sleep#

Thanks for any advice.
Last edited by sl23 on September 21st, 2022, 4:10 pm, edited 1 time in total.
User avatar
balala
Rainmeter Sage
Posts: 14585
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Problem with IfMatch

Post by balala »

sl23 wrote: September 20th, 2022, 12:33 pm I tried adding an IfCondition to the time measure, which didn't work.
An IfCondition=(#CURRENTSECTION#=4.25) option does work, but only if the Time measure where it is used has a proper format. For instance the following measure will execute the bangs set into the IfTrueAction option at the time given into the IfCondition option. Note that the time has a dot between the hour and minut, not a colon. This is needed to can handle the value returned by the measure as a number:

Code: Select all

[MeasureTime]
Measure=Time
Format=%H.%M
IfCondition=(#CURRENTSECTION#=4.25)
IfTrueAction=[BANGS TO EXECUTE WHEN CONDITON IS MET]
To get this properly working you have to use a 24-hour time format, a 12-hour format can be harder used.
If this doesn1t help, please post a full code of your skin.
User avatar
sl23
Posts: 1038
Joined: February 17th, 2011, 7:45 pm
Location: a Galaxy S7 far far away

Re: Problem with IfMatch

Post by sl23 »

Thanks balala. I did try your suggestion previously, but I'm using 12hr format - %#I:%M maybe that's why it didn't work for me?

Using 12 format just means it works twice a day doesn't it? But as pc won't be on in early hours that doesn't matter. Or does it work differently?
User avatar
balala
Rainmeter Sage
Posts: 14585
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Problem with IfMatch

Post by balala »

sl23 wrote: September 20th, 2022, 1:58 pm Thanks balala. I did try your suggestion previously, but I'm using 12hr format - %#I:%M maybe that's why it didn't work for me?
I doubt it wouldn't work with the measure used on 12-hour format. It should work with it. If doesn't post the code please, when you get home.
sl23 wrote: September 20th, 2022, 1:58 pm Using 12 format just means it works twice a day doesn't it? But as pc won't be on in early hours that doesn't matter. Or does it work differently?
If you don't use a %p on the Format option, there is nothing wrong with the 12-hour format. As you noticed in such a case the condition will be met twice a day and the action would be executed also twice a day, but if from these two cases one is out of your program and the computer is anyway shutdown at that moment, it's alright.
User avatar
sl23
Posts: 1038
Joined: February 17th, 2011, 7:45 pm
Location: a Galaxy S7 far far away

Re: Problem with IfMatch

Post by sl23 »

I've given it a try but need to wait until the time approaches as I'm quite busy! :oops:
User avatar
balala
Rainmeter Sage
Posts: 14585
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Problem with IfMatch

Post by balala »

sl23 wrote: September 20th, 2022, 2:18 pm I've given it a try but need to wait until the time approaches as I'm quite busy! :oops:
Alright. Just please let me know if you succeeded when it's the time.
User avatar
sl23
Posts: 1038
Joined: February 17th, 2011, 7:45 pm
Location: a Galaxy S7 far far away

Re: Problem with IfMatch

Post by sl23 »

Home now, and er... Nope, wasn't a success! Very odd! Any idea why? I did get this working in 2015,but deleted the skin as it wasn't required any longer. Something this simple shouldn't be this hard surely?! Lol

Out of curiosity, why is the IfMatch working like a timer instead of as it should?
User avatar
balala
Rainmeter Sage
Posts: 14585
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Problem with IfMatch

Post by balala »

sl23 wrote: September 20th, 2022, 4:07 pm Home now, and er... Nope, wasn't a success! Very odd! Any idea why?
How could I? Post a code please, without it can't say anything.
sl23 wrote: September 20th, 2022, 4:07 pm Out of curiosity, why is the IfMatch working like a timer instead of as it should?
What do you mean by IfMatch working like a timer? And how should it work?
User avatar
sl23
Posts: 1038
Joined: February 17th, 2011, 7:45 pm
Location: a Galaxy S7 far far away

Re: Problem with IfMatch

Post by sl23 »

Ok so here's the full code:

Code: Select all

[Rainmeter]
Update=1000
AccurateText=1
MouseActionCursor=0
BackgroundMode=2
SolidColor=255,255,255
MouseOverAction=[!ToggleMeterGroup Power] [!UpdateMeter *] [!Redraw]
MouseLeaveAction=[!ToggleMeterGroup Power] [!UpdateMeter *] [!Redraw]
RightMouseUpAction=[!TraMenu]
SkinWidth=150
SkinHeight=55

[Metadata]
Name=Clock + Shutdown
Author=sl23
Information=Clock with Shutdown.||
Version=2022.9.20
License=CC BY 3.0

[Variables]
Black=0,0,0
Trans=0,0,0,1

Shutdown.=250,150,150
Restart.=100,200,100
Sleep.=150,150,250
Lock.=235,170,100

Shutdown=shutdown.exe -s -t 00 -f
Restart=shutdown.exe -r -t 0
Sleep=rundll32.exe powrprof.dll,SetSuspendState
Lock=rundll32.exe user32.dll, LockWorkStation

Startup=shell:Startup
OFF=4.25.00

========================================
; Time
========================================
[mTime]
Measure=Time
Format=%#I:%M:%S
;IfMatch=#OFF#
;IfMatchAction=#Sleep#
IfCondition=(#CURRENTSECTION#=#OFF#)
IfTrueAction=#Sleep#

[Time]
Meter=String
MeasureName=mTime
FontFace=Trebuchet MS
StringStyle=Bold
StringAlign=CenterCenter
FontSize=25
FontColor=#Black#
;SolidColor=120,120,120
AntiAlias=1
Text=%1

LeftMouseUpAction=[!RefreshApp]
LeftMouseDoubleClickAction=#Startup#
MiddleMouseUpAction=[!Quit]
;ToolTipText="L - Refresh#CRLF#M - Exit"

X=75
Y=20
H=28

========================================
; SHUTDOWN
========================================
[sShut]
Shape=Rectangle 0,0,10,10,5 | Extend FillColor | StrokeWidth 2 | Extend StrokeAlpha
FillColor=Fill Color [#[#CURRENTSECTION]]
StrokeAlpha=Stroke Color #Trans#

MouseOverAction=[!SetOption #CURRENTSECTION# StrokeAlpha "Stroke Color #Black#"] [!UpdateMeter *][!Redraw]
MouseLeaveAction=[!SetOption #CURRENTSECTION# StrokeAlpha ""] [!UpdateMeter *] [!Redraw]
DynamicVariables=1

ToolTipText=#CURRENTSECTION#
Group=Power
Hidden=1
X=15r
Y=r

[Shutdown.]
Meter=Shape
MeterStyle=sShut
LeftMouseUpAction=#Shutdown#
X=-26r
Y=18r

[Restart.]
Meter=Shape
MeterStyle=sShut
LeftMouseUpAction=#Restart#

[Sleep.]
Meter=Shape
MeterStyle=sShut
LeftMouseUpAction=#Sleep#

[Lock.]
Meter=Shape
MeterStyle=sShut
LeftMouseUpAction=#Lock#
Wow that was a quick reply! I was just posting the code and was stopped by your response ;)

Well, when I used the IfMatch it put the PC into Sleep mode every 4.25 mins, why would it do that? That is acting like a timer. It shouldn't do that. It should work like I am describing, set a time and the PC is put to Sleep.

EDIT:
I've just edited the code as I forgot to copy the skin code from the work PC before I left. Just in case you are in the midst of replying!
User avatar
balala
Rainmeter Sage
Posts: 14585
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Problem with IfMatch

Post by balala »

sl23 wrote: September 20th, 2022, 4:14 pm Well, when I used the IfMatch it put the PC into Sleep mode every 4.25 mins, why would it do that? That is acting like a timer. It shouldn't do that. It should work like I am describing, set a time and the PC is put to Sleep.

EDIT:
I've just edited the code as I forgot to copy the skin code from the work PC before I left. Just in case you are in the midst of replying!
No, I were not...
Your IfMatch solution does work here, and I don't get the action re-executed after every 4.25 minutes, so don't exactly what to say. For now I let it more than 20 minutes and still no re-execution. I don't see a reason for such an action, but how knows...
However, what could you try is to use IfCondition instead. For this replace the [mTime] measure as it follows:

Code: Select all

[mTime]
Measure=Time
Format=%#I.%M%S
IfCondition=(#CURRENTSECTION#=#OFF#)
IfTrueAction=#Sleep#
RegExpSubstitute=1
Substitute="^(\d{1,2})\.(\d{2})(\d{2})$":"\1:\2:\3"
As you can see I replaced the Format option of this measure with Format=%#I.%M%S. I had to do this to get the measure returning a decimal number. The integer part is the hour, the first two decimals are the minutes, while the last two are the seconds. To get the measure returning the time into the "classic" format (with hours:minutes:seconds), I had to add a Substitute option. The result is in the known form, however, there still is a problem: the OFF variable has to be added in the new format, so in your case as OFF=4.2500. This can be fixed, to can use the variable in the time format, but this requires add inga new (for instance Calc) measure to the code. If you don't realize how to do this, but you'd like it, please let me know.
When testing, make sure you don't forget to replace the OFF variable in the [Variables] section.
Please test this solution if you are interested and let me know if does work.