It is currently June 8th, 2023, 7:49 pm

Dynamic variables in RunCommand parameter

Get help with installing and using Rainmeter.
mistic100
Posts: 34
Joined: October 12th, 2014, 5:27 pm

Dynamic variables in RunCommand parameter

Post by mistic100 »

Hello Rainmeter community,

I have a feature request for the official RunCommand plugin, please move this thread if it is not the right category.

Some context : I want to display an "dynamic" SVG available on the web (https://s3.coinmarketcap.com/generated/sparklines/web/7d/usd/74.svg). I use the WebParser to get the file, no problem here.
As the Image meter does not support SVG (that would be another feature request actually), I want to use ImageMagick to generate a PNG.

This was my first try :

Code: Select all

; download SVG
[MeasureSparklineSvg]
Measure=WebParser
UpdateRate=600
Url=https://s3.coinmarketcap.com/generated/sparklines/web/7d/usd/[&MeasureQuoteId].svg
Download=1
Paused=1
DynamicVariables=1
FinishAction=[!UpdateMeasure MeasureSparklinePng][!CommandMeasure MeasureSparklineConvert "Run"]

; build PNG file path
[MeasureSparklinePng]
Measure=String
UpdateDivider=-1
String=[MeasureSparklineSvg]
DynamicVariables=1
RegExpSubstitute=1
Substitute="svg$":"png"

; convert SVG to PNG
[MeasureSparklineConvert]
Measure=Plugin
Plugin=RunCommand
UpdateDivider=-1
Parameter=magick convert -background transparent [MeasureSparklineSvg] [MeasureSparklinePng]
DynamicVariables=1
OutputType=ANSI
This does not work, the return value of ImageMagick indicates the command was only

Code: Select all

magick convert -background transparent
without any values.

However I am able to make it work with a intermediary variable, but it is a bit harder to read :

Code: Select all

[Variables]
MagickCommand=

; download SVG
[MeasureSparklineSvg]
Measure=WebParser
UpdateRate=600
Url=https://s3.coinmarketcap.com/generated/sparklines/web/7d/usd/[&MeasureQuoteId].svg
Download=1
Paused=1
DynamicVariables=1
FinishAction=[!UpdateMeasure MeasureSparklinePng]

; build PNG file path
[MeasureSparklinePng]
Measure=String
UpdateDivider=-1
String=[MeasureSparklineSvg]
DynamicVariables=1
RegExpSubstitute=1
Substitute="svg$":"png"
OnUpdateAction=[!SetVariable MagickCommand "magick convert -background transparent [MeasureSparklineSvg] [MeasureSparklinePng]"][!UpdateMeasure MeasureSparklineConvert][!CommandMeasure MeasureSparklineConvert "Run"]

; convert SVG to PNG
[MeasureSparklineConvert]
Measure=Plugin
Plugin=RunCommand
UpdateDivider=-1
Parameter=#MagickCommand#
DynamicVariables=1
OutputType=ANSI
So to summarize I would like to be able to use section variables RunCommand#Parameter like WebParser#Url. Unless I missed something obvious ?

Thank you.
Last edited by mistic100 on November 3rd, 2022, 7:42 pm, edited 1 time in total.
User avatar
nek
Posts: 91
Joined: November 3rd, 2019, 12:00 am

Re: Dynamic variables in RunCommand parameter

Post by nek »

While skin is loading, [MeasureSparklineConvert](Runcommand) got "" (blank) as [MeasureSparklineSvg](WebParser)'s value.
It need to be updated before !CommandMeasure since [MeasureSparklineConvert](Runcommand) has UpdateDivider=-1 option.

I don't test but it should work in your 1st code.
FinishAction=[!UpdateMeasure MeasureSparklinePng][!UpdateMeasure MeasureSparklineConvert][!CommandMeasure MeasureSparklineConvert "Run"]

📗 RunCommand, WebParser
mistic100
Posts: 34
Joined: October 12th, 2014, 5:27 pm

Re: Dynamic variables in RunCommand parameter

Post by mistic100 »

Yup that does work. I though the parameter would be evaluated when the plugin runs, but now thinking about it, it makes sense, the plugin only accesses the last values of the measure.

Thank you very much.
User avatar
nek
Posts: 91
Joined: November 3rd, 2019, 12:00 am

Re: Dynamic variables in RunCommand parameter

Post by nek »

mistic100 wrote: November 3rd, 2022, 7:46 pm the plugin only accesses the last values of the measure.
How a skin is updated by jsmorley

It might be better something like this:

Code: Select all

[Rainmeter]
OnRefreshAction=[!EnableMeasureGroup gAction]

[MeasureSparklineSvg]
Measure=WebParser
; FinishAction=[!UpdateMeasure MeasureSparklinePng][!UpdateMeasure MeasureSparklineConvert][!CommandMeasure MeasureSparklineConvert "Run"]
FinishAction=[!UpdateMeasure MeasureSparklinePng]

; build PNG file path
[MeasureSparklinePng]
Measure=String
Group=gAction
OnUpdateAction=[!UpdateMeasure MeasureSparklineConvert][!CommandMeasure MeasureSparklineConvert "Run"]
Disabled=1

; convert SVG to PNG
[MeasureSparklineConvert]
Measure=Plugin
Plugin=RunCommand

📗 Dynamic Cheat Sheet