It is currently April 23rd, 2024, 1:47 pm

Rainmeter Lua Script via MouseOver event

Get help with creating, editing & fixing problems with skins
Fuzzyketchup
Posts: 4
Joined: July 7th, 2017, 8:23 pm

Rainmeter Lua Script via MouseOver event

Post by Fuzzyketchup »

I have a Lua Script that I am trying to run with Rainmeter. Currently the script runs and I can see my .txt file's one line "Notes" get a Caesar Cipher applied to it, and then the Update() function will change the ScriptMeter Text field to match the output Cipher.

What I can't seem to find out is how to call this script on a MouseOverAction with Rainmeter. Additionally if I can use a MouseOverAction can I have it call a specific function?

My plan is to apply the Cipher in a loop on the mouse over event while the mouse is over it, and to undo the Cipher to illegible text when I remove the mouse.

MyLua.ini

Code: Select all

[ScriptMeasure]
Measure=Script
ScriptFile="#@#Scripts\MyLua.lua"

[StringStyle]
 FontFace=Trebuchet MS
 FontColor=255,245,207,255
 SolidColor=0,0,0,1
 StringStyle=Bold
 StringAlign=Center
 AntiAlias=1
 FontSize=20

[ScriptMeter]
Meter=String
MeterStyle=StringStyle
MeasureName=ScriptMeasure
Text=""
x=100
y=40

MyLua.lua

Code: Select all

function Initialize()
    FilePath = SKIN:ReplaceVariables("#@#Scripts/MyLua.txt")
    f = io.open(FilePath) --open the file, ovewrites the file each time
    str = f:read('*l') --read line
    f:close()
    --number = string.match(str, 1) --use a pattern search to find the first number in the file
    print(str) --test code


    encrypted = caesar.encrypt(str, 7)
    decrypted = caesar.decrypt(encrypted, 7)
    print("Original text:  ", str)
    print("Encrypted text: ", encrypted)
    print("Decrypted text: ", decrypted)
    output = encrypted


end --funciton Initialize

function Update()

    print(output)
    SKIN:Bang('!SetOption', 'ScriptMeter', 'Text', output)
    --return(output) --return the string

end

function encrypt(text, key)
    return text:gsub("%a", function(t)
            local base = (t:lower() == t and string.byte('a') or string.byte('A'))

            local r = t:byte() - base
            r = r + key
            r = r%26 -- works correctly even if r is negative
            r = r + base
            return string.char(r)
        end)
end

local function decrypt(text, key)
    return encrypt(text, -key)
end

caesar = {
    encrypt = encrypt,
    decrypt = decrypt,
}

MyLua.txt

Code: Select all

Notes
Fuzzyketchup
Posts: 4
Joined: July 7th, 2017, 8:23 pm

Re: Rainmeter Lua Script via MouseOver event

Post by Fuzzyketchup »

A member of Reddit by the name of /u/GlobTwo helped me figure this out, so I figured I'd post his response here too.

Code: Select all

MouseOverAction=[!CommandMeasure "ScriptMeasure" "encrypt('sometext', '1')"]