It is currently July 27th, 2024, 8:04 am

Struggling to convert meter to number (EmailCheckerSimple)

Get help with creating, editing & fixing problems with skins
birkoffsjunk
Posts: 7
Joined: June 8th, 2013, 2:06 pm

Struggling to convert meter to number (EmailCheckerSimple)

Post by birkoffsjunk »

EmailCheckerSimple plugin uses a meter to get all data (as far as I can see, I might wrong here).
I'm trying to take the new mail count from the meter, use that to set a variable, and then use that variable within a measure.

So far, I've gotten the variable set correctly, however the measure doesn't function.

Any help would be greatly appreicated

Code: Select all

[Variables]
FriendlyName=Proton
Domain=Proton.me
ClickLink=mail.proton.me
NewMailColour=255,0,0,255
NoNewMailColour=255,255,255,255

NumberOfEmails=0
emailDiv=180


[msEmail]
Measure=Plugin
Plugin=EmailCheckerSimple
UpdateDivider=180
Delay=0
PerAccountMaxMessages=1
TotalMaxMessages=4
Separators=0

; Specify your accounts using numbered properties:

; ------- Proton
Name0=Proton
ServerAddress0=
ServerType0=IMAP
Port0=1143
IgnoreBadCert0=1
Security0=none
Username0=
Password0=
Active0=1

[mEmail]
Meter=String
Text=[&msEmail:GetData("(count)")]
OnUpdateAction=[!SetVariable NumberOfEmails [&msEmail:GetData("(count)")]]
UpdateDivider=#emailDiv#
DynamicVariables=1
Hidden=1



[MeasureCountEmails]
Measure=Calc
Formula=#NumberOfEmails#+0
UpdateRate=1
IfAboveValue=0
IfAboveAction=[!SetOption Icon GreyScale "0"][!SetOption Domainname FontColor #NewMailColour#][!SetOption Icon ImageTint "255,255,255,255"][!UpdateMeter Icon][!UpdateMeter Domainname][!Redraw]
IfEqualValue=0
IfEqualAction=[!SetOption Icon GreyScale "1"][!SetOption Domainname FontColor #NoNewMailColour#][!SetOption Icon ImageTint "255,255,255,150"][!UpdateMeter Icon][!UpdateMeter Domainname][!Redraw]
DynamicVariables=1


[Domainname]
Meter=STRING
FontColor=#NoNewMailColour#
Text="#FriendlyName#"
FontFace=Myriad Pro
FontSize=12
StringStyle=BOLD
StringEffect=Shadow
FontEffectColor=0,0,0,100
AntiAlias=1
X=0
Y=8

[Icon]
Meter=IMAGE
ImageName=#CURRENTSECTION#.png
X=0R
Y=0
W=32
H=32
LeftMouseUpAction=[#ClickLink#]
MiddleMouseUpAction=[!Refresh]
ToolTipTitle=#Domain#
ToolTipType=0
ToolTipIcon=INFO
ToolTipText="You have [MeasureCountEmails] new messages!"
DynamicVariables=1
User avatar
Yincognito
Rainmeter Sage
Posts: 7785
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Struggling to convert meter to number (EmailCheckerSimple)

Post by Yincognito »

birkoffsjunk wrote: May 21st, 2024, 7:06 pm EmailCheckerSimple plugin uses a meter to get all data (as far as I can see, I might wrong here).
I'm trying to take the new mail count from the meter, use that to set a variable, and then use that variable within a measure.

So far, I've gotten the variable set correctly, however the measure doesn't function.
Didn't (and won't, due to data sensitivity) test the code, but once the variable was set correctly, you'd typically update the measure using it, as well as other sections using or displaying it, and optionally redraw the skin (didn't add the latter since that part exists in the measure's If...Actions anyway):

Code: Select all

OnUpdateAction=[!SetVariable NumberOfEmails [&msEmail:GetData("(count)")]][!UpdateMeasure MeasureCountEmails]
By the way, UpdateRate makes no sense and doesn't exist in a Calc measure.

References (note the behavior of IfActions):
- https://docs.rainmeter.net/manual/measures/general-options/ifactions/
- https://docs.rainmeter.net/manual/measures/calc/
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
birkoffsjunk
Posts: 7
Joined: June 8th, 2013, 2:06 pm

Re: Struggling to convert meter to number (EmailCheckerSimple)

Post by birkoffsjunk »

Forgot about the update measure bang and to remove updaterate (was from older measure I replaced). Thanks, unfortunately makes no difference to the skin.

I did notice in the logs I'm getting Calc: Syntax error (imap.ini - [MeasureCountEmails])
I'm probably being dumb but Formula=0+#NumberOfEmails# shouldn't cause a problem?
User avatar
Yincognito
Rainmeter Sage
Posts: 7785
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Struggling to convert meter to number (EmailCheckerSimple)

Post by Yincognito »

birkoffsjunk wrote: May 21st, 2024, 8:13 pm I did notice in the logs I'm getting Calc: Syntax error (imap.ini - [MeasureCountEmails])
I'm probably being dumb but Formula=0+#NumberOfEmails# shouldn't cause a problem?
No, it shouldn't cause any problem, but only if the variable has a numeric value in the first place (which you implied that it does, since you said that you did set the variable correctly). If it doesn't, then that part in the formula will be the literal "#NumberOfEmails#" string, which will obviously throw the error you mentioned.

Now, as I said, I don't know if and how you get that number, or what the [&msEmail:GetData("(count)")] is providing, but you can see the value of different measures and variables in the Skins tab from the About Rainmeter window:
https://docs.rainmeter.net/manual/user-interface/about/#SkinsTab
and that should help you in debugging where the problem comes from.

By the way, if the above error occurs only at skin load / refresh time, then this is normal, since in that moment, the data (including the number of emails) might not be retrieved yet. So basically, you have a problem only if the error occurs every time [mEmail] is updated (which, according to the current code, is every 180 seconds, aka every 3 minutes).

Personally, I would avoid redundancy and directly use [&msEmail:GetData("(count)")] in the Formula option from [MeasureCountEmails], move the OnUpdateAction there if you really need the NumberOfEmails variable or just omit it if you don't, and simply reference this measure going forward, like you did in the [Icon] tooltip for example. Assuming everything on the plugin side (e.g. syntax, options, etc.) is correct, the code should work.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
birkoffsjunk
Posts: 7
Joined: June 8th, 2013, 2:06 pm

Re: Struggling to convert meter to number (EmailCheckerSimple)

Post by birkoffsjunk »

[&msEmail:GetData("(count)")] is outputing not just a number but also includes hidden formatting like #CRLF# which I think is the source of all my issues.

I have no clue how to clean the output or the variable.
User avatar
Yincognito
Rainmeter Sage
Posts: 7785
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Struggling to convert meter to number (EmailCheckerSimple)

Post by Yincognito »

birkoffsjunk wrote: May 22nd, 2024, 11:22 pm [&msEmail:GetData("(count)")] is outputing not just a number but also includes hidden formatting like #CRLF# which I think is the source of all my issues.

I have no clue how to clean the output or the variable.
Yeah, that would be the cause. Use your OP code and replace your [mEmail] with:

Code: Select all

[mEmail]
Measure=String
String=[&msEmail:GetData("(count)")]
RegExpSubstitute=1
Substitute="\R":""
OnUpdateAction=[!SetVariable NumberOfEmails [mEmail]]
UpdateDivider=#emailDiv#
DynamicVariables=1
I suggest using the same UpdateDivider=#emailDiv# in your [MeasureCountEmails] measure instead of the invalid UpdateRate option, so that updating it won't be necessary since it comes after [mEmail] in the code.

As for the Substitute, since you didn't specify exactly how the output looks like, I only added removing the newline characters aka \R in regular expression (also called regex or regexp) syntax, but you can add to it or replace it with a regex pattern more appropriate to what you want to remove from your [&msEmail:GetData("(count)")] output:
https://docs.rainmeter.net/manual/measures/general-options/substitute/

Despite their scary look, regular expressions are just patterns made of normal / literal characters and various symbols, which are used to find or replace parts of a string. More information about it at:
https://en.wikipedia.org/wiki/Regular_expression
https://www.regular-expressions.info/
Or, if you want to test and play with them:
https://regex101.com/
https://regexr.com/
By the way, Rainmeter uses the PCRE flavor of the regular expressions, so this flavor must be chosen in the testing sites (the buttons at top left for regex101.com and top right for regexr.com) to get the results that you'd get in Rainmeter. Also, you can check what various symbols or patterns mean on both regex101.com and regexr.com (on the latter by using the RegEx Reference button from the sidebar on the left side of the page).
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
birkoffsjunk
Posts: 7
Joined: June 8th, 2013, 2:06 pm

Re: Struggling to convert meter to number (EmailCheckerSimple)

Post by birkoffsjunk »

Thanks for this, instantly got the skin working. Looks like I had actually been on the right path but my regex-foo is weak.

For reference here is the completed skin should it be useful for anyone else in the future.

Code: Select all

[Rainmeter]
Author=birkoffsjunk
Update=1000

[Metadata]
Name=imap_checker
Description=IMAP Checker via EmailCheckerSimple
Version=1.0
License=The MIT License (MIT)

[Variables]
FriendlyName=
Domain=
ClickLink=
NewMailColour=189,6,6,255
NoNewMailColour=255,255,255,160
emailDiv=60



[msEmail]
Measure=Plugin
Plugin=EmailCheckerSimple
UpdateDivider=#emailDiv#
Delay=0
PerAccountMaxMessages=1
TotalMaxMessages=4
Separators=0

; Specify your accounts using numbered properties:

; ------- Proton
Name0=Proton
ServerAddress0=
ServerType0=IMAP
Port0=
IgnoreBadCert0=1
Security0=none
Username0=
Password0=
Active0=1


[mEmail]
Measure=String
String=[&msEmail:GetData("(count)")]
RegExpSubstitute=1
Substitute="\R":"","":"0"
UpdateDivider=#emailDiv#
IfAboveValue=0
IfAboveAction=[!SetOption Icon GreyScale "0"][!SetOption Domainname FontColor #NewMailColour#][!SetOption Icon ImageTint "255,255,255,255"][!UpdateMeter Icon][!UpdateMeter Domainname][!Redraw]
IfEqualValue=0
IfEqualAction=[!SetOption Icon GreyScale "1"][!SetOption Domainname FontColor #NoNewMailColour#][!SetOption Icon ImageTint "255,255,255,150"][!UpdateMeter Icon][!UpdateMeter Domainname][!Redraw]
DynamicVariables=1





[Domainname]
Meter=STRING
FontColor=#NoNewMailColour#
Text="#FriendlyName#"
FontFace=Myriad Pro
FontSize=12
StringStyle=BOLD
StringEffect=Shadow
FontEffectColor=0,0,0,100
AntiAlias=1
X=0
Y=8

[Icon]
Meter=IMAGE
ImageName=#CURRENTSECTION#.png
X=0R
Y=0
W=32
H=32
LeftMouseUpAction=[#ClickLink#]
MiddleMouseUpAction=[!Refresh]
ToolTipTitle=#Domain#
ToolTipType=0
ToolTipIcon=INFO
ToolTipText="You have [mEmail] new messages!"
DynamicVariables=1
Removed the NumberOfEmails variable
Consolidated extra measures into one
Added extra substitution to fix always new mail bug
User avatar
Yincognito
Rainmeter Sage
Posts: 7785
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Struggling to convert meter to number (EmailCheckerSimple)

Post by Yincognito »

birkoffsjunk wrote: May 23rd, 2024, 7:34 pm Thanks for this, instantly got the skin working. Looks like I had actually been on the right path but my regex-foo is weak.
Excellent, nice modifications to eliminate pointless redundancy - thanks for sharing the final implementation for others that might be interested! Yeah, regex is not that user friendly at first look, but it's an useful and powerful tool to manipulate strings. :thumbup:
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth