Please check DeviantArt page for details. In short, RainWake is a WakeOnLan single click skin. It can be used to remotely open a computer, given that it has been configured correctly. On the Rainmeter developing side, it is my first time I write a .lua script. It is used to create the necessary wol .bat files. Also, the skin uses a .vbs file to completely hide the short appearance of the cmd window (making it a way to run an invisible cmd command). Lastly, you can insert the necessary information with InputText plugin, without messing with the skin's files.
PLEASE comment on my first try in .lua & critique my code.
Last but not least, this is an example skin; I don't like the look of it very much either. But I would love to see prettier skins.
BTW: You retrieve but do not use the variables Bat and WoL.
GitHub | DeviantArt | Tumblr
This is the song that never ends. It just goes on and on my friends. Some people started singing it not knowing what it was, and they'll continue singing it forever just because . . .
Oh! I already found some ground breaking breathroughs for my infant .lua mind. Multiple "variable data" in one variable (Vars)? Ηow did you manage to narrow this down to a single line code?
As for the variables WoL and Bat, you are right. I used them in a previous version of the script but I forgot to scratch them out. Leaving them out will make the code look like this, I guess:
function Initialize()
Vars={'CURRENTPATH';'MAC';'IP';'Port'}
for i=1,#Vars do Vars[i]=SKIN:GetVariable(Vars[i]) end
if Vars[2]~='XX-XX-XX-XX-XX-XX' and Vars[3]~='0.0.0.0' and Vars[4]~='0' then
sMAC, _ = string.gsub(Vars[2],(string.find(Vars[2],'-') and '-' or ':'), '')
MyFile = io.open(Vars[1]..'Resources/Wolcmd/wol.bat' ,'w+')
if MyFile then
MyFile:write ('wolcmd '..sMAC..' '..Vars[3]..' 255.255.255.255 '..Vars[4])
else
print('Can\'t create file: wol.bat')
return 'File Error'
end
MyFile:close()
MyFile2 = io.open(Vars[1]..'Resources/Wolcmd/invisible.vbs' ,'w+')
if MyFile2 then
MyFile2:write ('Set WshShell = CreateObject("WScript.Shell") \n cmds=WshShell.RUN("""'..Vars[1]..'Resources/Wolcmd/wol.bat'..'""", 0, True) \n Set WshShell = Nothing')
else
print('Can\'t create file: invisible.vbs')
return 'File Error'
end
MyFile2:close()
else
print("You should edit all RainWake fields")
end
end
Inactive, due to life changes. Send me a PM for any question.
string.find(Vars[2],'-') and '-' or ':'
This is basically the same as conditional?true:false
If the string contains '-' then use '-' else ':'
That was the difference you used in your original code.
Now, I believe we can actually skip this test altogether by using: string.gsub(Vars[2],'[-:]', '')
What this should do is remove all instances of '-' or ':'
In your original code you had it substituting for "" which is the same as '', which I prefer.
function Initialize()
Vars={'CURRENTPATH';'MAC';'IP';'Port'}
for i=1,#Vars do Vars[i]=SKIN:GetVariable(Vars[i]) end
if Vars[2]~='XX-XX-XX-XX-XX-XX' and Vars[3]~='0.0.0.0' and Vars[6]~='0' then
MyFile=io.open(Vars[1]..'Resources/Wolcmd/wol.bat','w+')
if MyFile then
MyFile:write('wolcmd '..string.gsub(Vars[2],'[-:]','')..' '..Vars[3]..' 255.255.255.255 '..Vars[4])
else
print('Can\'t create file: wol.bat')
return 'File Error'
end
MyFile:close()
MyFile2=io.open(Vars[1]..'Resources/Wolcmd/invisible.vbs','w+')
if MyFile2 then
MyFile2:write('Set WshShell = CreateObject("WScript.Shell") \n cmds=WshShell.RUN("""'..Vars[1]..'Resources/Wolcmd/wol.bat'..'""", 0, True) \n Set WshShell = Nothing')
else
print('Can\'t create file: invisible.vbs')
return 'File Error'
end
MyFile2:close()
else
print('You should edit all RainWake fields')
end
end
GitHub | DeviantArt | Tumblr
This is the song that never ends. It just goes on and on my friends. Some people started singing it not knowing what it was, and they'll continue singing it forever just because . . .
Thanks for the latest code, smurfier, it's fully used into my skin now (note to other users: there's a small typo in the above code, Vars[6]~='0' should be Vars[4]~='0')
Other than that, I three skin variants and linked one to the other, so that I could create an easy way of "multiple" remote PC configurations. Given that I didn't want to spend any more time on this skin, it does it's job.
Inactive, due to life changes. Send me a PM for any question.
Mordasius wrote:I found it was easier to input the PC Name, MAC, etc. if you change to FontSize=7 in [InputName], [InputMAC], etc.
Really? This is how mine looks with fontsize=7:
Perhaps I have made a mistake while creating the .rmskin file and the font didn't installed correctly? Roboto was installed on your machine?
Mordasius wrote:Of course what I'd really like is to have something like this to switch off a remote computer so I can steal all the bandwidth on our LAN.
Heh, I would like that, too. The cmd way of shutting down a remote PC requires authentication, as I understand. So an ugly cmd window will appear, I think. If anyone wants to tackle that, feel free. I mainly use PC Monitor or Teamviewer to shutdown my remote machines.
Inactive, due to life changes. Send me a PM for any question.
KreAch3R wrote:Really? This is how mine looks with fontsize=7:
Sorry, my bad. I had a custom DPI setting of 125% which affects the font size displayed when using the InputText plugin.
Thanks for the tip about authentication. I'll have to sneak around when they're out to open TCP port 445 and check the 'Allow users to connect remotely to this computer' box. Mind you, I don't think it will be very long before they become suspicious.