It is currently May 6th, 2024, 10:42 pm

Variable variables

Get help with creating, editing & fixing problems with skins
sh8an
Posts: 1
Joined: September 21st, 2011, 6:53 am

Variable variables

Post by sh8an »

Hi all
i am new to rainmeter, so might be a stupid question.
simple case:
[Variables]
show=hide
hide=show
sysinfo.state=hide

then any meter, for example like this

Code: Select all

[Test.1]
Meter=STRING
x=0
y=70r
FontColor=#white#
Text=#sysinfo.state#
DynamicVariables=1
LeftMouseUpAction=!Execute [nircmd.exe win #sysinfo.state# title "System Information"][!SetVariable "sysinfo.state" "##sysinfo.state##"]
obviously it doesn't work. so my question is there any way to do variable variables with rainmeter?

ps. if escaped, the value stays escaped
thanks in advance
poiru
Developer
Posts: 2872
Joined: April 17th, 2009, 12:18 pm

Re: Variable variables

Post by poiru »

You could use the Script measure to achieve something like this.

Skin .ini file:

Code: Select all

[mLua]
Measure=Script
ScriptFile=Test.lua

...

[SomeMeter]
LeftMouseUpAction=!Execute [!CommandMeasure "mLua" "ToggleWindow()"]
Test.lua file (in same directory as skin .ini):

Code: Select all

function ToggleWindow()
	SKIN:Bang('!Execute [nircmd.exe win #sysinfo.state# title "System Information"]')

	local newState
	if SKIN:GetVariable('sysinfo.state') == 'hide' then
		newState = 'show'
	else
		newState = 'hide'
	end

	SKIN:Bang('!SetVariable sysinfo.state ' .. newState)
end
User avatar
MerlinTheRed
Rainmeter Sage
Posts: 889
Joined: September 6th, 2011, 6:34 am

Re: Variable variables

Post by MerlinTheRed »

Does your example mean you don't need the Update and Initialize functions if you only use the script in !CommandMeasure Bangs?
Have more fun creating skins with Sublime Text 2 and the Rainmeter Package!
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Variable variables

Post by jsmorley »

Initialize() is run once when the skin is loaded / refreshed and Update() is run on each Update= of the skin. However, you can certainly call a Lua script that contains only a function using !CommandMeasure, and just have it execute the function and return.

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1

[MeasureLua]
Measure=Script
ScriptFile="#CURRENTPATH#test.lua"
Disabled=1

[MeterDateTime]
Meter=String
FontSize=13
FontColor=255,255,255,255
SolidColor=0,0,0,1
Text=ClickMe
LeftMouseUpAction=!CommandMeasure MeasureLua "DateTime();"
function DateTime()

SKIN:Bang('!SetOption MeterDateTime Text """' .. os.date() .. '"""')

end -- function Test
User avatar
Kaelri
Developer
Posts: 1721
Joined: July 25th, 2009, 4:47 am

Re: Variable variables

Post by Kaelri »

An alternative method that I use in my skins:

Code: Select all

[Variables]
sysinfo.state=1

[MeasureSysInfoState]
Measure=Calc
Formula=#sysinfo.state#
Substitute="1":"show","0":"hide"
DynamicVariables=1

...

LeftMouseUpAction=!Execute [nircmd.exe win [MeasureSysInfoState] title "System Information"][!SetVariable sysinfo.state (1-#sysinfo.state#)]
Poiru's method is certainly cleaner, and easier to adapt to other cases. But this works great when all you need is to toggle a pair of values.