It is currently April 18th, 2024, 5:19 pm

running a program to update an MeterImage

Get help with creating, editing & fixing problems with skins
medvejonok
Posts: 8
Joined: December 4th, 2017, 5:37 pm

running a program to update an MeterImage

Post by medvejonok »

Hello Community,

this sounds quite trivial but I have not succeeded yet in getting it to work.

Some images are stored on an external web server. I would like to create skins that download them regularly and keep them displayed on the desktop. Sounds trivial!

To overcome the usual secure authenticated proxy problems that prevent the WebParser plugin from downloading the images (the "official" way),
I have found a method using a PowerShell script, you can actually invoke Powershell on the command line (the syntax is powershell.exe iwr -outf PATH_TO_LOCAL_TARGET_PNG https://PATH_TO_WWW_SOURCE_PNG). This works on the command line, the correct image gets downloaded to the correct place.

So... how do you write a correct Rainmeter skin that will invoke the PowerShell command regularly (e.g. every 15mins) to save the image to #@#/myimage.png and keep a MeterImage up to date displaying that file?

I have tried various strategies using Measure=Plugin, Plugin=RunCommand, OnUpdateAction in the MeterImage section, etc, but nothing seems to happen, the command ends up never being launched in my scripts. Then there is no image to display and nothing happens.

Thanks in advance if anyone can suggest a skeleton script that works!

:bow:
User avatar
balala
Rainmeter Sage
Posts: 16144
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: running a program to update an MeterImage

Post by balala »

It would be much easier for us to help you, if we would know the PATH_TO_WWW_SOURCE_PNG. Could you please post it?
medvejonok
Posts: 8
Joined: December 4th, 2017, 5:37 pm

Re: running a program to update an MeterImage

Post by medvejonok »

Hi balala

thank you for your reply,
unfortunately I cannot share the real link but here is a test image that is exactly in the same style of setup:

https://storage.googleapis.com/trdemo/testimage.png

if you need the contents of the image to be made to change regularly I can rig this up but may need a couple of days.

Thanks!
User avatar
balala
Rainmeter Sage
Posts: 16144
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: running a program to update an MeterImage

Post by balala »

This testimage is downloaded by Rainmeter with no problem. Doesn't this work with the original source?
An example code:

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

[MeasureImage]
Measure=Plugin
Plugin=WebParser
Url=https://storage.googleapis.com/trdemo/testimage.png
Download=1
UpdateRate=1800

[MeterImage]
Meter=Image
MeasureName=MeasureImage
medvejonok
Posts: 8
Joined: December 4th, 2017, 5:37 pm

Re: running a program to update an MeterImage

Post by medvejonok »

No, unfortunately I am behind an authenticated proxy, so cannot use the WebParser plugin.

The solution would be to run
powershell.exe iwr -outf PATH_TO_LOCAL_TARGET_PNG https://PATH_TO_WWW_SOURCE_PNG
every time the image needs refreshing

I have not succeeded in getting Rainmeter to run this, and to use this command to refresh and reload the image to be displayed.
medvejonok
Posts: 8
Joined: December 4th, 2017, 5:37 pm

Re: running a program to update an MeterImage

Post by medvejonok »

I suppose ultimately if rainmeter cannot do this, I could use a scheduler to run the powershell script independently, and then get rainmeter to just display the local image?

However it would be much better if this could all be bundled in the same skin to avoid the image download running when it is not necessary because the skin is not running either.
User avatar
balala
Rainmeter Sage
Posts: 16144
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: running a program to update an MeterImage

Post by balala »

medvejonok wrote:I suppose ultimately if rainmeter cannot do this, I could use a scheduler to run the powershell script independently, and then get rainmeter to just display the local image?
Yeah, you could, however Rainmeter can use the described method to download the image. See the following code:

Code: Select all

[Rainmeter]
Update=-1

[Variables]

[MeasureRun]
Measure=Plugin
Plugin=RunCommand
Program=powershell.exe 
Parameter=iwr -outf PATH_TO_LOCAL_TARGET_PNG https://PATH_TO_WWW_SOURCE_PNG
State=Hide

[MeterDownload]
Meter=STRING
MeasureName=MeasureRun
X=50
Y=20
Padding=15,5,15,5
FontColor=220,220,220
SolidColor=0,0,0,150
FontSize=14
FontFace=Segoe UI
StringStyle=BOLD
StringAlign=CENTERCENTER
AntiAlias=1
Text=Click to#CRLF#download
LeftMouseUpAction=[!CommandMeasure "MeasureRun" "Run"]
Be careful, this code has the Update set to -1, probably this won't be very convenient for your needs. But for now, it is good enough, I think.
The code, through the [MeasureRun] plugin measure, downloads the image, using the PowerShell. Yet it does the download only when you're clicking the Click to download string. Please try this code and let me know if it works. If it does, we'll furtherly develop it, to make it to work as you want.
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: running a program to update an MeterImage

Post by jsmorley »

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1
OnRefreshAction=[!CommandMeasure MeasureGetImage "Run"]

[Variables]
InImage=https://wallpapers.wallhaven.cc/wallpapers/full/wallhaven-596635.jpg
OutImage=#CURRENTPATH#DownloadedImage.png

[MeasureGetImage]
Measure=Plugin
Plugin=RunCommand
Parameter=powershell.exe iwr -outf "#OutImage#" "#InImage#"
FinishAction=[!SetOption MeterImage ImageName "#OutImage#"][!UpdateMeter MeterImage]

[MeterImage]
Meter=Image
W=400
PreserveAspectRatio=1
1.png
Edit: Balala sorta beat me to it.. ;-)
You do not have the required permissions to view the files attached to this post.
medvejonok
Posts: 8
Joined: December 4th, 2017, 5:37 pm

Re: running a program to update an MeterImage

Post by medvejonok »

Many thanks to both of you, this support is so helpful!

This helps resolve the question of authenticated proxies not working with Webparser plugin. Thanks again.
User avatar
balala
Rainmeter Sage
Posts: 16144
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: running a program to update an MeterImage

Post by balala »

medvejonok wrote:Many thanks to both of you, this support is so helpful!

This helps resolve the question of authenticated proxies not working with Webparser plugin. Thanks again.
Glad to help, if you got it working well.