A primer on "quotes" in Rainmeter
Posted: February 14th, 2018, 6:01 pm
One of the things that can be a bit confusing to a new Rainmeter user is when to "quote" strings that you use. Let's touch on that and see if we can simplify it.
Rainmeter never needs "quotes" around option values
The first thing to be aware of is that Rainmeter doesn't pay the slightest bit of attention to starting and ending "quotes" around option values. By that I mean things like:
FontColor="255,255,255,255"
ImageName="#@#Images\My Image.png"
Text="Hello World"
Drive="C:"
Interface="Qualcomm Atheros AR938x Wireless Network Adapter"
RegExp="(?siU)<title>(.*)</title>"
Doesn't matter a bit if there is "white space" (spaces or tabs) in the value, those beginning and ending "quotes" are just not needed. In fact, the very first thing Rainmeter will do is strip them off and throw them away. They are just ignored. The above can and should be defined as:
FontColor=255,255,255,255
ImageName=#@#Images\My Image.png
Text=Hello World
Drive=C:
Interface=Qualcomm Atheros AR938x Wireless Network Adapter
RegExp=(?siU)<title>(.*)</title>
Why is this? It's because an option value is always a single thing. It is always a single string value to Rainmeter, and the "quotes" are not needed because they are assumed by the program. In other words, Rainmeter knows the values are strings, and you don't have to tell it so like you would in a programming language where you might say myVar="Hello World". In that case, you have to tell the language that the variable myVar is a string. In Rainmeter, you never do. They are all strings, even FontSize=12, or W=100. Rainmeter knows when an option requires a number, and will itself turn the string "12" into the number 12 as needed. You don't have to worry about it.
So not to get too far into the weeds, just keep this simple rule in mind. Rainmeter never, ever needs starting and ending quotes around option values.
What about [Variable] values?
There is no difference. The things defined in [Variables] are just Option=Value like anything on a measure or meter. Never use starting and ending quotes on variable definitions. They are just stripped off and thrown away.
Won't white space in values like paths to a file cause problems?
NO. Rainmeter is perfectly fine with ImageName=#@#Images\My Image.png. By the definition of the option, it knows that a path to a file is expected, and it will deal with it properly when it asks Windows for the file behind the scenes. Starting and ending "quotes" are just not needed. Again, they are just thrown away.
So when do I actually need "quotes" around a string in Rainmeter?
The only time you will in fact need "quotes" around a string in Rainmeter is when the string value is a parameter to a bang, and the string value contains white space (spaces or tabs).
Bad:
LeftMouseUpAction=[!SetOption MyMeter ImageName #@#Images\My Image.png]
Good:
LeftMouseUpAction=[!SetOption MyMeter ImageName "#@#Images\My Image.png"]
So what is the difference? It's the fact that there are multiple "parameters" supported in bangs, and white space will confuse Rainmeter about where a parameter starts and ends. In that example above, the !SetOption bang, as most do, supports a final optional parameter of "config name", which tells it which skin / config you want the bang to operate on. With the white space in the path above, Rainmeter can't know if Image.png is still part of the path, or the name of the config to act upon. The "quotes" around the value resolves this ambiguity.
When the !SetOption bang actually sets the value for the option ImageName on the meter, it will be set without the quotes. Again, they are just not needed on option values. The quotes are there to help Rainmeter "parse" the bang parameters. Nothing else.
So the rule here is that you should always enclose string parameters in bangs in "quotes". Even if there is no white space in the value, it's a good habit to get in. This habit will be particularly useful, and will save a lot of head-scratching, when you dynamically use [SectionVariables] or #Variables# in the parameters in a bang. Are you SURE there aren't, or won't ever be, spaces in that value?
That's it really. Just keep these two rules in mind:
1) Rainmeter never needs starting and ending "quotes" around option values
2) Always enclose string parameters in bangs in "quotes"
Rainmeter never needs "quotes" around option values
The first thing to be aware of is that Rainmeter doesn't pay the slightest bit of attention to starting and ending "quotes" around option values. By that I mean things like:
FontColor="255,255,255,255"
ImageName="#@#Images\My Image.png"
Text="Hello World"
Drive="C:"
Interface="Qualcomm Atheros AR938x Wireless Network Adapter"
RegExp="(?siU)<title>(.*)</title>"
Doesn't matter a bit if there is "white space" (spaces or tabs) in the value, those beginning and ending "quotes" are just not needed. In fact, the very first thing Rainmeter will do is strip them off and throw them away. They are just ignored. The above can and should be defined as:
FontColor=255,255,255,255
ImageName=#@#Images\My Image.png
Text=Hello World
Drive=C:
Interface=Qualcomm Atheros AR938x Wireless Network Adapter
RegExp=(?siU)<title>(.*)</title>
Why is this? It's because an option value is always a single thing. It is always a single string value to Rainmeter, and the "quotes" are not needed because they are assumed by the program. In other words, Rainmeter knows the values are strings, and you don't have to tell it so like you would in a programming language where you might say myVar="Hello World". In that case, you have to tell the language that the variable myVar is a string. In Rainmeter, you never do. They are all strings, even FontSize=12, or W=100. Rainmeter knows when an option requires a number, and will itself turn the string "12" into the number 12 as needed. You don't have to worry about it.
So not to get too far into the weeds, just keep this simple rule in mind. Rainmeter never, ever needs starting and ending quotes around option values.
What about [Variable] values?
There is no difference. The things defined in [Variables] are just Option=Value like anything on a measure or meter. Never use starting and ending quotes on variable definitions. They are just stripped off and thrown away.
Won't white space in values like paths to a file cause problems?
NO. Rainmeter is perfectly fine with ImageName=#@#Images\My Image.png. By the definition of the option, it knows that a path to a file is expected, and it will deal with it properly when it asks Windows for the file behind the scenes. Starting and ending "quotes" are just not needed. Again, they are just thrown away.
So when do I actually need "quotes" around a string in Rainmeter?
The only time you will in fact need "quotes" around a string in Rainmeter is when the string value is a parameter to a bang, and the string value contains white space (spaces or tabs).
Bad:
LeftMouseUpAction=[!SetOption MyMeter ImageName #@#Images\My Image.png]
Good:
LeftMouseUpAction=[!SetOption MyMeter ImageName "#@#Images\My Image.png"]
So what is the difference? It's the fact that there are multiple "parameters" supported in bangs, and white space will confuse Rainmeter about where a parameter starts and ends. In that example above, the !SetOption bang, as most do, supports a final optional parameter of "config name", which tells it which skin / config you want the bang to operate on. With the white space in the path above, Rainmeter can't know if Image.png is still part of the path, or the name of the config to act upon. The "quotes" around the value resolves this ambiguity.
When the !SetOption bang actually sets the value for the option ImageName on the meter, it will be set without the quotes. Again, they are just not needed on option values. The quotes are there to help Rainmeter "parse" the bang parameters. Nothing else.
So the rule here is that you should always enclose string parameters in bangs in "quotes". Even if there is no white space in the value, it's a good habit to get in. This habit will be particularly useful, and will save a lot of head-scratching, when you dynamically use [SectionVariables] or #Variables# in the parameters in a bang. Are you SURE there aren't, or won't ever be, spaces in that value?
That's it really. Just keep these two rules in mind:
1) Rainmeter never needs starting and ending "quotes" around option values
2) Always enclose string parameters in bangs in "quotes"