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: Select all
(Get-Content "test.ini" -Raw) + "`r`n[Meter5] `nMeter=Shape `nMeterStyle=Meterstyle" | Set-Content "test.ini"
log.txt
Code: Select all
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: Select all
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: Select all
[Add]
Measure=Plugin
Plugin=RunCommand
Program=PowerShell
Parameter=(Get-Content "test.ini" -Raw) "`r`n[Meter5] `nMeter=Shape `nMeterStyle=Meterstyle" | Set-Content "test.ini"
State=Hide
OutputType=UTF8
OutputFile=log.txt
Edit.
Well, I changed the approach and this worked:
Code: Select all
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: Select all
[Rainmeter]
Update=-1
AccurateText=1
[Metadata]
Name= Test
Author= RicardoTM
Information= Create and Delete meters.
Version= 1.0
License= Creative Commons Attribution - Non - Commercial - Share Alike 3.0
[Variables]
N=4
[MeterStyle]
Shape=Rectangle 0,0,100,20
y=R
[Less]
Measure=Plugin
Plugin=RunCommand
Program=PowerShell.exe
Parameter=(Get-Content Test.ini -Raw) -replace '(?s)\[Meter[#N]\].*?;---' | ForEach-Object { $_.TrimEnd() } | Set-Content Test.ini -Encoding UTF8
State=Hide
OutputFile=log.txt
OutputType=UTF8
FinishAction=[!WriteKeyValue Variables N ([#N]-1)][!Refresh]
[Add]
Measure=Plugin
Plugin=RunCommand
Program=PowerShell
Parameter=Add-Content "Test.ini" "`n[Meter$([#N]+1)]`nMeter=Shape`nMeterStyle=Meterstyle`n`;---"
State=Hide
OutputType=UTF8
OutputFile=log.txt
FinishAction=[!WriteKeyValue Variables N ([#N]+1)][!Refresh]
[Button]
meter=shape
Shape=Rectangle 0,0,20,20 | Fill Color 125,0,0 | StrokeWidth 0
x=110
LeftMouseUpAction=[!CommandMeasure Less run]
[Button2]
meter=shape
Shape=Rectangle 0,0,20,20 | Fill Color 0,125,0 | StrokeWidth 0
x=130
LeftMouseUpAction=[!CommandMeasure Add run]
[Meter]
Meter=Shape
MeterStyle=MeterStyle
x=0
y=0
[Meter1]
Meter=Shape
MeterStyle=MeterStyle
;---
[Meter2]
Meter=Shape
MeterStyle=MeterStyle
;---
[Meter3]
Meter=Shape
MeterStyle=Meterstyle
;---
[Meter4]
Meter=Shape
MeterStyle=Meterstyle
;---