It is currently February 19th, 2020, 11:40 am

Action on skin "load" but not "refresh"

Tips and Tricks from the Rainmeter Community
User avatar
jsmorley
Developer
Posts: 20250
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Action on skin "load" but not "refresh"

Post by jsmorley »

The OnRefreshAction in the [Rainmeter] section of a skin can be used to fire bangs or other commands when a skin is first loaded and on each refresh.

However, there may be a case were you want an action to execute when a skin is first loaded, but not each time when it is refreshed thereafter. In effect a distinct OnLoadAction, which doesn't (and due to backwards compatibility issues at this point, really can't) exist.

There is a way to use the internal Counter function in Rainmeter to solve this.

The Counter function in a Calc measure will return the number of skin "updates" that have taken place since the skin was loaded. This counter is not reset to zero when the skin is refreshed.

Code: Select all

[MeasureOnLoad]
Measure=Calc
Formula=Counter
IfEqualValue=1
IfEqualAction=[Some bangs or commands]
UpdateDivider=-1
This measure will fire the bangs or commands when the internal Counter is at "1", which it will be on the first update of the skin. It will never fire again while the skin is running, even if refreshed. The UpdateDivider=-1 is just to maximize efficiency, as the measure will then only even be evaluated on the first update of the skin, and just "go to sleep" after that.
User avatar
fonpaolo
Moderator
Posts: 1338
Joined: April 11th, 2013, 8:08 pm
Location: Italy

Re: Action on skin "load" but not "refresh"

Post by fonpaolo »

Thanks! :thumbup: :D
I've tried many solutions, but I had not yet thought about this solution!
User avatar
jsmorley
Developer
Posts: 20250
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Action on skin "load" but not "refresh"

Post by jsmorley »

The UpdateDivider=-1 also allows you to use this measure to have distinct "OnLoad" and "OnRefesh" actions, each only executing once when the skin is either loaded or refreshed.

Code: Select all

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

[MeasureOnLoad]
Measure=Calc
Formula=Counter
IfEqualValue=1
IfEqualAction=[!SetOption MeterStatus Text "Skin Loaded at Update [MeasureOnLoad]"]
IfAboveValue=1
IfAboveAction=[!SetOption MeterStatus Text "Skin Refreshed at Update [MeasureOnLoad]"]
UpdateDivider=-1

[MeterStatus]
Meter=String
FontSize=12
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
One design consideration to keep in mind. If there is a conflict between this measure and an actual OnRefreshAction in [Rainmeter], the OnRefreshAction will be executed "last", and in a sense will then "win" any conflicts that are based on the order of events. OnRefreshAction is in effect executed "right after" the very first skin update, where this measure will be executed "during" the very first skin update.
AmbientMike
Posts: 23
Joined: October 18th, 2016, 2:26 pm

Re: Action on skin "load" but not "refresh"

Post by AmbientMike »

Hi,

I can't seem to get this to work. My Skin always seems to wait the update time before running the Measure. I'm sure it's my Skin rather than the function. Can anyone suggest why it's not working as intended?

Code: Select all

[Rainmeter]
Update=10000
DynamicWindowSize=10
AccurateText=1
BackgroundMode=2
SkinWidth=334
SolidColor=0,0,0,45

[MeasureOnLoad]
Measure=Calc
Formula=Counter
IfEqualValue=1
IfEqualAction=[!CommandMeasure MeasureBootTime "Run"][!UpdateMeter MeterBootTime]
UpdateDivider=-1

[MeasureMoveSkin]
Measure=Calc
Formula=#SCREENAREAWIDTH@1#
IfAboveValue=0
IfAboveAction=[!Move "(#SCREENAREAX@1#+#SCREENAREAWIDTH@1#-#CURRENTCONFIGWIDTH#-10)" ("#SCREENAREAY@1#+10")]
OnChangeAction=[!Move "(#SCREENAREAX@1#+#SCREENAREAWIDTH@1#-#CURRENTCONFIGWIDTH#-10)" ("#SCREENAREAY@1#+10")]
DynamicVariables=1

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

[MeasureBootTime]
Measure=Plugin
Plugin=RunCommand
Parameter=For /F "tokens=3,4" %G in ('net statistics workstation ^| %WINDIR%\system32\find.exe /I "Statistics since"') DO ECHO %G %H
State=Hide
RegExpSubstitute=1
Substitute="(?siU)^.*ECHO.*(\d+/\d+/\d+ \d+:\d+:\d+)\s+.*$":"\1"

[MeterBootTime1]
Meter=String
Padding=10,5,15,5
FontSize=12
FontColor=255,255,255,255
StringStyle=Bold
AntiAlias=1
Text=Boot Time:
X=0
Y=0R

[MeterBootTime]
Meter=String
MeasureName=MeasureBootTime
X=#CURRENTCONFIGWIDTH#
Y=0r
W=#CURRENTCONFIGWIDTH#
StringAlign=Right
Padding=10,5,15,5
FontSize=12
FontColor=255,255,255,255
StringStyle=Bold
AntiAlias=1
Text=%1
EDIT - Adding...
FinishAction=[!UpdateMeter MeterBootTime][!Redraw]
... to the Measure fixed it. Sorry.
User avatar
eclectic-tech
Rainmeter Sage
Posts: 3759
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: Action on skin "load" but not "refresh"

Post by eclectic-tech »

You are executing the RunCommand measure on load, and the results show in the !Log immediately. But the result will not appear in your string meter until the next update, which is 10 seconds later due to Update=10000 in your [Rainmeter] section.

To have it show immediately, add FinishAction=[!UpdateMeter MeterBootTime][!Redraw] to your [MeasureBootTime] measure.
You can remove those bangs [!UpdateMeter MeterBootTime][!Redraw] from the [MeasureOnLoad] section.

Code: Select all

[MeasureBootTime]
Measure=Plugin
Plugin=RunCommand
Parameter=For /F "tokens=3,4" %G in ('net statistics workstation ^| %WINDIR%\system32\find.exe /I "Statistics since"') DO ECHO %G %H
State=Hide
RegExpSubstitute=1
Substitute="(?siU)^.*ECHO.*(\d+/\d+/\d+ \d+:\d+:\d+)\s+.*$":"\1"
FinishAction=[!UpdateMeter MeterBootTime][!Redraw]

AmbientMike
Posts: 23
Joined: October 18th, 2016, 2:26 pm

Re: Action on skin "load" but not "refresh"

Post by AmbientMike »

Cheers. Yeah, I figured that all out a few minutes after posting. I still really struggle to get my head around Rainmeter. I'll get it eventually.
User avatar
eclectic-tech
Rainmeter Sage
Posts: 3759
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: Action on skin "load" but not "refresh"

Post by eclectic-tech »

Glad to see you figured it out :thumbup:

We all struggle learning something new, but thankfully, there usually is someone here to help! :welcome: