It is currently March 29th, 2024, 1:27 pm

RegEx wizards, help me out (with something to do with Windows powerplans)?

Get help with creating, editing & fixing problems with skins
jn_meter
Posts: 136
Joined: December 27th, 2016, 12:04 pm

RegEx wizards, help me out (with something to do with Windows powerplans)?

Post by jn_meter »

Dear all

I'd like a regEx that can take a measure's output and transform it as follows.

If the output is 1) a single string, containing no commas - such as My PowerPlan - then return that very string.

If alternatively the string 2) does contain commas, then return all and only the text after the last comma. For instance, were the output to be (as it can be): @%SystemRoot%\system32\powrprof.dll,-13,High Performance then I wish the output to be High Performance.

Here is the relevant part of my code. At present, in case 2, it just returns the whole string.

Code: Select all

;  ==== POWER PLAN  ====

[measure_powerPlan_activeScheme]
DynamicVariables=1
Measure=Registry
RegHKey=HKEY_LOCAL_MACHINE
RegKey=SYSTEM\ControlSet001\Control\Power\User\PowerSchemes
RegValue=ActivePowerScheme
UpdateDivider=#update_powerPlan_activeScheme#

[measure_powerPlan_activeScheme_name]
DynamicVariables=1
Measure=Registry
RegHKey=HKEY_LOCAL_MACHINE
RegKey=SYSTEM\ControlSet001\Control\Power\User\PowerSchemes\[measure_powerPlan_activeScheme]
The regEx I am after is magic having the following form.

Code: Select all

;  ==== POWER PLAN  ====

[measure_powerPlan_activeScheme]
DynamicVariables=1
Measure=Registry
RegHKey=HKEY_LOCAL_MACHINE
RegKey=SYSTEM\ControlSet001\Control\Power\User\PowerSchemes
RegValue=ActivePowerScheme
UpdateDivider=#update_powerPlan_activeScheme#

[measure_powerPlan_activeScheme_name]
DynamicVariables=1
Measure=Registry
RegHKey=HKEY_LOCAL_MACHINE
RegKey=SYSTEM\ControlSet001\Control\Power\User\PowerSchemes\[measure_powerPlan_activeScheme]
RegValue=FriendlyName
UpdateDivider=#update_powerPlan_activeScheme_name#
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: RegEx wizards, help me out (with something to do with Windows powerplans)?

Post by balala »

jn_meter wrote: May 10th, 2021, 10:14 pm I'd like a regEx that can take a measure's output and transform it as follows.

If the output is 1) a single string, containing no commas - such as My PowerPlan - then return that very string.

If alternatively the string 2) does contain commas, then return all and only the text after the last comma. For instance, were the output to be (as it can be): @%SystemRoot%\system32\powrprof.dll,-13,High Performance then I wish the output to be High Performance.
A regular expression substitution is needed, instead of a RegExp. Add the following two options to the [measure_powerPlan_activeScheme_name] measure:

Code: Select all

[measure_powerPlan_activeScheme_name]
...
RegExpSubstitute=1
Substitute="^.*,(.*)$":"\1"
jn_meter
Posts: 136
Joined: December 27th, 2016, 12:04 pm

Re: RegEx wizards, help me out (with something to do with Windows powerplans)?

Post by jn_meter »

balala: as ever, wonderful. Thank you very much.
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: RegEx wizards, help me out (with something to do with Windows powerplans)?

Post by balala »

Great, I'm glad.
User avatar
Fajn
Posts: 2
Joined: May 9th, 2022, 12:17 am

Re: RegEx wizards, help me out (with something to do with Windows powerplans)?

Post by Fajn »

Hi, I'm totaly new to making my own skins.
I was looking for a way to show current active power plan, for my power plan changing widget.

I just do not know how am I supposed to get the name of the active powerplan from the code above.

Here is my code:

Code: Select all

;===Power plan detection===
[measure_powerPlan_activeScheme]
DynamicVariables=1
Measure=Registry
RegHKey=HKEY_LOCAL_MACHINE
RegKey=SYSTEM\ControlSet001\Control\Power\User\PowerSchemes
RegValue=ActivePowerScheme
UpdateDivider=#update_powerPlan_activeScheme#

[measure_powerPlan_activeScheme_name]
DynamicVariables=1
Measure=Registry
RegHKey=HKEY_LOCAL_MACHINE
RegKey=SYSTEM\ControlSet001\Control\Power\User\PowerSchemes\[measure_powerPlan_activeScheme]
RegValue=FriendlyName
UpdateDivider=#update_powerPlan_activeScheme_name#
RegExpSubstitute=1
Substitute="^.*,(.*)$":"\1"

;===Variables===
[Variables]
BackgroundColor=22,22,22,220
PowerPlansColor=245,245,245,222
PowerPlansColor2=225,225,225,150
PowerPlansFont=Calibri
PowerPlansFontSize=12

[StyleFont]
FontColor=#PowerPlansColor#
FontFace=#PowerPlansFont#
FontSize=#PowerPlansFontSize#
StringStyle=Bold
AntiAlias=1

;===Widget===
[CurrPWP]
Meter=STRING
X=10
Y=12
Text=[measure_powerPlan_activeScheme_name]
MeterStyle=StyleFont
Thanks for any help, I am sure it will be really easy and that I am just dump. ;-)
jn_meter
Posts: 136
Joined: December 27th, 2016, 12:04 pm

Re: RegEx wizards, help me out (with something to do with Windows powerplans)?

Post by jn_meter »

I think you need to do the following. First, delete the following line from your meter:

Code: Select all

Text=[measure_powerPlan_activeScheme_name]
Second, add these lines to that same meter:

Code: Select all

MeasureName=measure_powerPlan_activeScheme_name
Text=%1
User avatar
Fajn
Posts: 2
Joined: May 9th, 2022, 12:17 am

Re: RegEx wizards, help me out (with something to do with Windows powerplans)?

Post by Fajn »

Thank you very much. You helped me a lot.
Also, I hope, that this answer will help any futurecomers which might have similar question as you and me.

Aagin, thanks a lot. :D
jn_meter
Posts: 136
Joined: December 27th, 2016, 12:04 pm

Re: RegEx wizards, help me out (with something to do with Windows powerplans)?

Post by jn_meter »

Jolly good. Just don't ask me to explain the correction! :?