It is currently May 6th, 2024, 10:42 pm
Get help with creating, editing & fixing problems with skins
sh8an
Posts: 1 Joined: September 21st, 2011, 6:53 am
Post
by sh8an » September 21st, 2011, 7:32 am
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
Post
by poiru » September 21st, 2011, 9:57 am
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
MerlinTheRed
Rainmeter Sage
Posts: 889 Joined: September 6th, 2011, 6:34 am
Post
by MerlinTheRed » September 21st, 2011, 12:44 pm
Does your example mean you don't need the Update and Initialize functions if you only use the script in !CommandMeasure Bangs?
jsmorley
Developer
Posts: 22631 Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA
Post
by jsmorley » September 21st, 2011, 1:08 pm
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
Kaelri
Developer
Posts: 1721 Joined: July 25th, 2009, 4:47 am
Post
by Kaelri » September 21st, 2011, 1:59 pm
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.