It is currently April 24th, 2024, 5:13 pm

IfMatchAction=[!SetVarible SomeVariable "#SomeVariable#"]

Get help with creating, editing & fixing problems with skins
neo.nemek
Posts: 36
Joined: February 11th, 2023, 7:52 am

IfMatchAction=[!SetVarible SomeVariable "#SomeVariable#"]

Post by neo.nemek »

Well today I have to solve a problem with the instruction !SetVariable,
I have a Variable declared to 0 to define a parameter to be used in a Meter, what I'm trying to do is check a #Mail# Variable loaded from UserVariables.inc and find out if it has any data and depending on whether or not it has data, this Variable defines another Variable #MailClient# with some data expressed in the IfMatchAction, the code:

Code: Select all

[Variables]
@Include=#@#UserVariables.inc

;Declare Variable to open mail client
MailClient=0
........

; ====================
; [Measures]

[mCheckMail01-MailClient]
Measure=String
String=#Mail#
RegExpSubstitute=1
Substitute="^(.+)$":"enabled","^$":"disabled"
IfMatch="enabled"
IfMatchAction=[!Log "Mail client is configured MailClient: #MailClient#" Notice][!SetVariable MailClient "#Mail#"]
IfNotMatchAction=[!Log "No Mail client is configured Mail: #Mail#, WEBmail: #MailClient#" Notice][!SetVariable MailClient "http://Google......."]
UpdateDivider=-1
DynamicVariables=1

For me the code is correct but it does not work !SetVariable does not apply any data to the Variable #MailClient# I am blocked again and I tell you that I have read many topics with !SetVariable and how to use it. Once again thank you for your attention and help.
User avatar
SilverAzide
Rainmeter Sage
Posts: 2604
Joined: March 23rd, 2015, 5:26 pm

Re: IfMatchAction=[!SetVarible SomeVariable "#SomeVariable#"]

Post by SilverAzide »

neo.nemek wrote: February 25th, 2023, 11:09 pm
This code should work; I don't see any obvious errors. What does the About > Skin window show as the value of the variable?

If you are only looking at the log to see the message you are writing, then you may be misunderstanding how Rainmeter works (it can be quite confusing to understand!!!). For example, the bang [!Log "No Mail client is configured Mail: #Mail#, WEBmail: #MailClient#" Notice] is going to always output the same message, it will always say No Mail client is configured Mail: , ...WEBmail: 0 (if my guess is correct). This is because Rainmeter evaluated the variables when your .INI file was first read. For this bang to work as intended you need to take additional steps, which I won't go into quite yet.

To inspect variables, check the About > Skin screen. This screen should show that your code worked.
Gadgets Wiki GitHub More Gadgets...
User avatar
SilverAzide
Rainmeter Sage
Posts: 2604
Joined: March 23rd, 2015, 5:26 pm

Re: IfMatchAction=[!SetVarible SomeVariable "#SomeVariable#"]

Post by SilverAzide »

neo.nemek wrote: February 25th, 2023, 11:09 pm
Also, I don't think it is necessary to do what you are doing. I think your logic for detecting if the Mail variable is set would work just as well like so:

Code: Select all

[mCheckMail01-MailClient]
Measure=String
String=#Mail#
RegExpSubstitute=1
Substitute="^(.+)$":"enabled","^$":"disabled"
IfMatch="disabled"
IfMatchAction=[!Log "No mail client is configured." Notice][!SetVariable Mail "http://Google......."]
UpdateDivider=-1
DynamicVariables=1
Drop the use of the MailClient variable and just use Mail.

You could even simplify things more and just let the measure return the proper value, and use the measure instead of the variable where needed. Like so:

Code: Select all

[mMailClient]
Measure=String
String=#Mail#
RegExpSubstitute=1
Substitute="^$":"http://Google......."
UpdateDivider=-1
Now [mMailClient] will return the address, even if the #Mail# variable is a blank value. (On a skin that is for only yourself, this works OK, as you know the mail address. On a skin that can be used by others, you will not be able to set the Mail variable yourself, and you'll need to allow the skin to gracefully fail.)
Gadgets Wiki GitHub More Gadgets...
neo.nemek
Posts: 36
Joined: February 11th, 2023, 7:52 am

Re: IfMatchAction=[!SetVarible SomeVariable "#SomeVariable#"]

Post by neo.nemek »

Hello, it is true that it works but there was an error in the syntax of the code that sends the data of the Second Variable that I did not show in the initial post and that contains the web address of Google/Gmail

Code: Select all

[Variables]

@Include=#@#UserVariables.inc
@Include2=#@#Variables.inc
@Include3=#@#Translation.inc

Hide01=0
Hide02=1
Hide03=1
Hide04=1

;Variable to disable or enable Measures
Mail01-State=1
Mail02-State=1

;Variables to know if there is a user and password defined 0=Not Defined, 1=Defined
Mail01-User=0
Mail01-Pass=0
Mail02-User=0
Mail02-Pass=0

;Declare Variable to open mail client
WEBmail=http://mail.google.com/mail/ ;<-- (This Variable is not declared here it is in the UserVariables.inc file)
MailClient=0
.......

[mCheckMail-MailClient]
Measure=String
String=#Mail#
RegExpSubstitute=1
Substitute="^(.+)$":"enabled","^$":"disabled"
IfMatch="enabled"
IfMatchAction=[!Log "Mail client is configured" Notice][!SetVariable "MailClient" "#Mail#"]
IfNotMatchAction=[!Log "No Mail client is configured" Notice][!SetVariable MailClient "[#WEBmail#]"]
UpdateDivider=-1
DynamicVariables=1
......

[Mail01Count]
Meter=String
MeterStyle=Text
MeasureName=mMail01
X=50
Y=5
W=60
H=30
FontFace=#Primary Font#
FontColor=#Secondary Font Color#
FontSize=20
StringStyle=Bold
LeftMouseUpAction=[!SetVariable Hide01 1] [!SetVariable Hide02 0] [!SetVariable Hide03 0] [!SetVariable Hide04 1]
RightMouseDownAction=#MailClient#
DynamicVariables=1


Now The MailClient Variable always holds the correct syntax in any situation, good explanation of why all these checks on whether or not the Mail Variable has data.
Not only do I check that variable, I also check User and Pass of mCheckMail01, mCheckMail02, mCheckInternet because I am debugging errors that appear in the LOG of this Skin that checks Gmail.
And since I only want it to check the mail under certain conditions, that's why I check the UserVariables previously and Internet, the Skin will only check the mail if everything is fine and it will not do it if there is a missing data, also the Measures that check the start mail are deactivated and are only activated as I say if the User data is correct.

I enable the Measurement group with this code after the previous checks:

Code: Select all

[mCheckInternet]
Measure=Plugin
Plugin=SysInfo
SysInfoType=INTERNET_CONNECTIVITY
IfCondition=(mCheckInternet = -1)
IfTrueAction=[!Log "No Internet available" Notice][!SetVariable Mail01-State "1"][!SetVariable Mail02-State "1"]
IfCondition2=(mCheckInternet = 1) && (#Mail01-User# = 1) && (#Mail01-Pass# = 1)
IfTrueAction2=[!Log "Mail01 update possible" Notice][!SetVariable Mail01-State "0"][!EnableMeasureGroup "MeasureMail01"][!UpdateMeasureGroup "MeasureMail01"]
IfCondition3=(mCheckInternet = 1) && (#Mail02-User# = 1) && (#Mail02-Pass# = 1)
IfTrueAction3=[!Log "Mail02 update possible" Notice][!SetVariable Mail02-State "0"][!EnableMeasureGroup "MeasureMail02"][!UpdateMeasureGroup "MeasureMail02"]
DynamicVariables=1

[!EnableMeasureGroup "MeasureMail01"][!UpdateMeasureGroup "MeasureMail01"] , Is there another better way to enable and update them with !EnableMeasureGroup !UpdateMeasureGroup ???, Is it correct to use this code to update the Measures?
neo.nemek
Posts: 36
Joined: February 11th, 2023, 7:52 am

Re: IfMatchAction=[!SetVarible SomeVariable "#SomeVariable#"]

Post by neo.nemek »

Sometimes Rainmeter and its code perplexes me!!! I'm making a Measure that controls the number of messages that are reflected in a Meter because I don't want them to appear. Example 1500 messages as data, well, I think I'll make a Measure that collects the data and I set conditions like this:

Code: Select all

[mCheckInbox01]
Measure=Calc
Formula=mMail01
IfCondition=mMail01 >= 1000
IfTrueAction=[!SetVariable Mail01-Inbox "999"]
IfCondition2=mMail01 <= 999
IfTrueAction2=[!SetVariable Mail01-Inbox "[mMail01]"]
DynamicVariables=1

[mMail01]
Measure=Plugin
Plugin=WebParser
Url=http://#Gmail User 01#:#Gmail Password 01#@gmail.google.com/gmail/feed/atom
RegExp="(?siU)<fullcount>(.*)</fullcount>.*<title.*>(.*)</title>.*<link.*href="(.*)".*<entry.*<title.*>(.*)</title>.*<link.*href="(.*)"(?(?=.*<entry>).*<title.*>(.*)</title>.*<link.*href="(.*)")(?(?=.*<entry>).*<title.*>(.*)</title>.*<link.*href="(.*)")(?(?=.*<entry>).*<title.*>(.*)</title>.*<link.*href="(.*)")(?(?=.*<entry>).*<title.*>(.*)</title>.*<link.*href="(.*)")(?(?=.*<entry>).*<title.*>(.*)</title>.*<link.*href="(.*)")(?(?=.*<entry>).*<title.*>(.*)</title>.*<link.*href="(.*)")(?(?=.*<entry>).*<title.*>(.*)</title>.*<link.*href="(.*)")(?(?=.*<entry>).*<title.*>(.*)</title>.*<link.*href="(.*)")(?(?=.*<entry>).*<title.*>(.*)</title>.*<link.*href="(.*)")(?(?=.*<entry>).*<title.*>(.*)</title>.*<link.*href="(.*)")"
UpdateRate=900
StringIndex=1
Substitute="":"0"
Group=MeasureMail01
Disabled=#Mail01-State#
..............
[Mail01Count]
Meter=String
MeterStyle=Text
X=50
Y=5
W=60
H=30
FontFace=#Primary Font#
FontColor=#Secondary Font Color#
FontSize=20
StringStyle=Bold
Text=#Mail01-Inbox#
LeftMouseUpAction=[!SetVariable Hide01 1] [!SetVariable Hide02 0] [!SetVariable Hide03 0] [!SetVariable Hide04 1]
RightMouseDownAction=#MailClient#
DynamicVariables=1

mCheckInbox01 controls the data that mMail01 gives and if there are more than 1000 I do a !SetVariable that points to Var Mail01-Inbox and sets it to "999" or if there are less than 999 Messages in mMail01 then the same thing but this time I want the Variable Mail01-Inbox have the real Data of mMail01

So far so good, but to test it and since I don't want Google to van my public IP, I do the tests without internet and change the code IfTrueAction2=[!SetVariable Mail01-Inbox "[mMail01]"] in this line. to IfTrueAction2=[!SetVariable Mail01-Inbox "[mMail01:+1]"] this returns 0.0 and Puts it in the Variable Mail01-Inbox,, and [Mail01Count] Meter displays it fine 0.0, I applaud and smile because apparently it works and since they are dynamic variables the Meter shows and updates its content according to the value of Mail01-Inbox.

Well I put the correct line again without the :+1 like this: IfTrueAction2=[!SetVariable Mail01-Inbox "[mMail01]"] and I connect internet [mMail01] it is updated to 152 Messages but the Meter does not show 152,,, shows 0 messages, uffff I am perplexed how can it be???
neo.nemek
Posts: 36
Joined: February 11th, 2023, 7:52 am

Re: IfMatchAction=[!SetVarible SomeVariable "#SomeVariable#"]

Post by neo.nemek »

After trying a thousand things and reading a thousand texts, my light bulb went on and I just had to implement a substitution Regex like this and put it in the Measure mMail01:

Code: Select all

[mMail01]
Measure=Plugin
Plugin=WebParser
Url=http://#Gmail User 01#:#Gmail Password 01#@gmail.google.com/gmail/feed/atom
RegExp=(?siU)<fullcount>(.*)</fullcount>.*<title.*>(.*)</title>.*<link.*href="(.*)".*<entry.*<title.*>(.*)</title>.*<link.*href="(.*)"(?(?=.*<entry>).*<title.*>(.*)</title>.*<link.*href="(.*)")(?(?=.*<entry>).*<title.*>(.*)</title>.*<link.*href="(.*)")(?(?=.*<entry>).*<title.*>(.*)</title>.*<link.*href="(.*)")(?(?=.*<entry>).*<title.*>(.*)</title>.*<link.*href="(.*)")(?(?=.*<entry>).*<title.*>(.*)</title>.*<link.*href="(.*)")(?(?=.*<entry>).*<title.*>(.*)</title>.*<link.*href="(.*)")(?(?=.*<entry>).*<title.*>(.*)</title>.*<link.*href="(.*)")(?(?=.*<entry>).*<title.*>(.*)</title>.*<link.*href="(.*)")(?(?=.*<entry>).*<title.*>(.*)</title>.*<link.*href="(.*)")(?(?=.*<entry>).*<title.*>(.*)</title>.*<link.*href="(.*)")
UpdateRate=900
StringIndex=1
RegExpSubstitute=1
Substitute="":"0","^\d{4}$":"999"
Group=MeasureMail01
Disabled=#Mail01-State#

Some friendly user of this forum could confirm that if the Measure offers a value of more than 3 digits, the Regex does its mission and is replaced by 999 and this Meter shows 999 as data ???

Code: Select all

[Mail01Count]
Meter=String
MeasureName=mMail01
MeterStyle=Text
X=50
Y=5
W=60
H=30
FontFace=#Primary Font#
FontColor=#Secondary Font Color#
FontSize=20
StringStyle=Bold
LeftMouseUpAction=[!SetVariable Hide01 1] [!SetVariable Hide02 0] [!SetVariable Hide03 0] [!SetVariable Hide04 1]
RightMouseDownAction=#MailClient#
DynamicVariables=1

I know that Regex works and it will only look for a 4-digit string, but since I can't put 1000 emails in my Gmail, I don't know how to test it

EDIT: I have already verified that the Regex will fulfill its function, I did the test looking for 3-digit strings just to see if I put 999 in the Meter and it showed 999 and yes, finally after a day battling with the problem I was able to discriminate any account that exceeds that the 1000 mail messages stored