It is currently March 28th, 2024, 10:34 pm

Script measure: New SKIN:Bang() syntax

Changes made during the Rainmeter 2.5 beta cycle and earlier.
poiru
Developer
Posts: 2872
Joined: April 17th, 2009, 12:18 pm

Script measure: New SKIN:Bang() syntax

Post by poiru »

Executing bangs through Lua is often cubersome, because the concatenation operator (i.e. ..) must be used repeatedly and because quotes must be properly escaped. As a result, you often end up with ugly lines such as:

Code: Select all

SKIN:Bang("!SetVariable " .. varName .. " \"" .. varValue "\"")
SKIN:Bang('!SetOption MeterTitle' .. i .. ' LeftMouseUpAction """!Execute [\" '.. tLinks[currentItem] .. '\"]"""')
In recent Rainmeter 2.3 betas, we've introduced an alternative form of SKIN:Bang() that greatly simplifies this. The line above can now be used rewritten as:

Code: Select all

SKIN:Bang("!SetVariable", varName, varValue)
SKIN:Bang('!SetOption', 'MeterTitle' .. i, 'LeftMouseUpAction', '[' .. tLinks[currentItem] .. ']')
In other words, instead of concatenating the bang parameters and escaping quotes, you can simply pass all parameters as actual parameters of the function. The result is much easier to both read and write.

Do note that in the "improved" !SetOption example, !Execute has been removed as it is now deprecated.
User avatar
XANCI
Posts: 104
Joined: September 18th, 2011, 6:37 am
Location: Nanjing, China

Re: Script measure: New SKIN:Bang() syntax

Post by XANCI »

Launching external application will fail

Code: Select all

SKIN:Bang('#@#RainRGB4.exe','VarName=ColorMain'..sP,'FileName=#CUSFILE#')
SKIN:Bang('control.exe','ncpa.cpl')
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Script measure: New SKIN:Bang() syntax

Post by jsmorley »

XANCI wrote:Launching external application will fail

Code: Select all

SKIN:Bang('#@#RainRGB4.exe','VarName=ColorMain'..sP,'FileName=#CUSFILE#')
SKIN:Bang('control.exe','ncpa.cpl')
The comma delimited parameters in the SKIN:Bang function are for parameters to Rainmeter bangs, not for parameters to external applications. Since what you are doing takes no Rainmeter parameters as such (like a !SetOption would for instance), you just need:

SKIN:Bang('[control.exe ncpa.cpl]')

Note that even though we got rid of !Execute, you should still use the brackets [] around Rainmeter bangs that call external applications.