Quantcast
Channel: Rainmeter Forums
Viewing all articles
Browse latest Browse all 752

Community Plugins & Addons • RunCommand

$
0
0
Well, I'm back lol. This time I'm experimenting on creating meters using PowerShell.
When I run this code in PowerShell it works, it writes the lines correctly, but if I do it in Rainmeter it doesn't.
Code:

Code:

(Get-Content "test.ini" -Raw) + "`r`n[Meter5] `nMeter=Shape `nMeterStyle=Meterstyle" | Set-Content "test.ini"
log.txt

Code:

On line: 1 Character: 30+ (Get-Content test.ini -Raw) + `r`n[Meter5] `rMeter=Shape `rMeterS ...+                                ~You must provide a value expression after the '+' operator.On line: 1 Character: 31+ (Get-Content test.ini -Raw) + `r`n[Meter5] `r`nMeter=Shape `r`nMeterS ...+                                ~~~~~~~~~~~~~~~~~~~~Unexpected token '`r`n[Meter5]' in the expression or statement.    + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException    + FullyQualifiedErrorId : ExpectedValueExpression
The problem seems to be with "+" and "`r`n". If I take them out it works but it writes everything in the same line including `r`n. Should I use some specific syntax for this case?.

When I take the "+" out:

Code:

On line: 1 Character: 29+ ... st.ini -Raw) `r`n[Meter5]`nMeter=Shape`nMeterStyle=Meterstyle | Set-C ...+                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Token '`r`n[Meter5]`nMeter=Shape`nMeterStyle=Meterstyle' in the expression or statement.    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException    + FullyQualifiedErrorId : UnexpectedToken
Sinces quotes " are necessary for the ` escape character to work on PowerShell, I also tried with double and triple quotes but no change.

This is the measure:

Code:

[Add]Measure=PluginPlugin=RunCommandProgram=PowerShell  Parameter=(Get-Content "test.ini" -Raw) "`r`n[Meter5] `nMeter=Shape `nMeterStyle=Meterstyle" | Set-Content "test.ini"State=HideOutputType=UTF8OutputFile=log.txt
Edit.
Well, I changed the approach and this worked:

Code:

Add-Content "test.ini" "`r`n[Meter5]`nMeter=Shape`nMeterStyle=Meterstyle"
Here's the complete code in case it is useful for someone else:

Test.ini

Code:

[Rainmeter]Update=-1AccurateText=1[Metadata]Name= TestAuthor= RicardoTMInformation= Create and Delete meters.Version= 1.0License= Creative Commons Attribution - Non - Commercial - Share Alike 3.0[Variables]N=4[MeterStyle]Shape=Rectangle 0,0,100,20y=R[Less]Measure=PluginPlugin=RunCommandProgram=PowerShell.exeParameter=(Get-Content Test.ini -Raw) -replace '(?s)\[Meter[#N]\].*?;---' | ForEach-Object { $_.TrimEnd() } | Set-Content Test.ini -Encoding UTF8State=HideOutputFile=log.txtOutputType=UTF8FinishAction=[!WriteKeyValue Variables N ([#N]-1)][!Refresh][Add]Measure=PluginPlugin=RunCommandProgram=PowerShell  Parameter=Add-Content "Test.ini" "`n[Meter$([#N]+1)]`nMeter=Shape`nMeterStyle=Meterstyle`n`;---"State=HideOutputType=UTF8OutputFile=log.txtFinishAction=[!WriteKeyValue Variables N ([#N]+1)][!Refresh][Button]meter=shapeShape=Rectangle 0,0,20,20 | Fill Color 125,0,0 | StrokeWidth 0x=110LeftMouseUpAction=[!CommandMeasure Less run][Button2]meter=shapeShape=Rectangle 0,0,20,20 | Fill Color 0,125,0 | StrokeWidth 0x=130LeftMouseUpAction=[!CommandMeasure Add run][Meter]Meter=ShapeMeterStyle=MeterStylex=0y=0[Meter1]Meter=ShapeMeterStyle=MeterStyle;---[Meter2]Meter=ShapeMeterStyle=MeterStyle;---[Meter3]Meter=ShapeMeterStyle=Meterstyle;---[Meter4]Meter=ShapeMeterStyle=Meterstyle;---

Statistics: Posted by RicardoTM — Today, 2:59 am — Replies 188 — Views 121147



Viewing all articles
Browse latest Browse all 752

Trending Articles