Page 1 of 1

PowerShellTime

Posted: January 18th, 2018, 3:24 am
by jsmorley
Just an example of running a PowerShell .ps1 script from Rainmeter... Speaks the date and time.
PowerShellTime_1.1.rmskin
Skin:

Code: Select all

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

[Variables]
Voice=female
;Voice=male

[MeasureTime]
Measure=Time
Format=%A, %B %#d, %Y at %#I:%M %p

[MeasureSpeakTime]
Measure=Time
Format=Today is %A, %B %#d`; %Y`. its %#I:%M %p.
RegExpSubStitute=1
Substitute="(?siU)(\w)(\w).$":"\1 \2"

[MeasureRun]
Measure=Plugin
Plugin=RunCommand
Program=PowerShell.exe
Parameter=-NoProfile -ExecutionPolicy Bypass -Command "& '.\SpeakTime.ps1' '[MeasureSpeakTime]' '#Voice#'"
OutputType=ANSI
DynamicVariables=1

[MeterTime]
Meter=String
MeasureName=MeasureTime
FontSize=11
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
DynamicVariables=1
SpeakTime.ps1:

Code: Select all

$time = $args[0]
$voice = $args[1]

Add-Type -AssemblyName System.speech
$speak = New-Object System.Speech.Synthesis.SpeechSynthesizer
$speak.SelectVoiceByHints($voice)
$speak.Rate = -1
$speak.Speak($time)
$speak.Dispose()

Re: PowerShellTime

Posted: January 18th, 2018, 3:27 pm
by SilverAzide
One comment or question...

The docs say that the RunCommand plugin uses the Command shell (cmd) to run commands by default, unless you set the Program parameter. If that is the case, to run this script, Rainmeter is going to run a Command shell to run a PowerShell... a shell inside a shell, which seems a little inefficient. So my thought/question is that for the purpose of running PowerShell (with or without scripts), it might be best to explicitly set the Program parameter; e.g. :

Code: Select all

[MeasureRun]
Measure=Plugin
Plugin=RunCommand
Program=PowerShell.exe
Parameter=-NoProfile -ExecutionPolicy Bypass -Command "& '.\SpeakTime.ps1' '[MeasureSpeakTime]' '#Voice#'"
OutputType=ANSI
DynamicVariables=1
Does that make sense?

Re: PowerShellTime

Posted: January 18th, 2018, 3:37 pm
by jsmorley
SilverAzide wrote:One comment or question...

The docs say that the RunCommand plugin uses the Command shell (cmd) to run commands by default, unless you set the Program parameter. If that is the case, to run this script, Rainmeter is going to run a Command shell to run a PowerShell... a shell inside a shell, which seems a little inefficient. So my thought/question is that for the purpose of running PowerShell (with or without scripts), it might be best to explicitly set the Program parameter; e.g. :

Code: Select all

[MeasureRun]
Measure=Plugin
Plugin=RunCommand
Program=PowerShell.exe
Parameter=-NoProfile -ExecutionPolicy Bypass -Command "& '.\SpeakTime.ps1' '[MeasureSpeakTime]' '#Voice#'"
OutputType=ANSI
DynamicVariables=1
Does that make sense?
Brian will have to weigh in, but I am under the impression that you can't avoid having cmd run in any case, as the whole thing is based on a ShellExcute, which will use the currently defined shell for Windows, which is cmd.exe, to launch whatever is defined in Program.

The way you have it certainly works, but I'm not entirely sure there is any real difference.

Re: PowerShellTime

Posted: January 18th, 2018, 3:51 pm
by jsmorley
No, you are right...

If you run this skin:

Code: Select all

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

[MeasureCMD]
Measure=Plugin
Plugin=Process
ProcessName=cmd.exe

[MeterCMD]
Meter=String
MeasureName=MeasureCMD
FontSize=11
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
and leave it running while you run that PowerShellTime skin both ways:

Code: Select all

[MeasureRun]
Measure=Plugin
Plugin=RunCommand
Parameter=PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& '.\SpeakTime.ps1' '[MeasureSpeakTime]' '#Voice#'"
OutputType=ANSI
DynamicVariables=1

Code: Select all

[MeasureRun]
Measure=Plugin
Plugin=RunCommand
Program=PowerShell.exe
Parameter=-NoProfile -ExecutionPolicy Bypass -Command "& '.\SpeakTime.ps1' '[MeasureSpeakTime]' '#Voice#'"
OutputType=ANSI
DynamicVariables=1
You will find that when you use the Program=PowerShell.exe option, cmd.exe is never executed. So that is better indeed.

I changed the .rmskin in the first post...

Re: PowerShellTime

Posted: May 4th, 2022, 12:34 pm
by jsmorley
TomShadow55 wrote: May 4th, 2022, 12:15 pm hello, I would like to know if it is possible to add a command so that the SpeakTime is activated every hour?
Just add this measure to the skin:

Code: Select all

[MeasureOnceAnHour]
Measure=Time
Format=%#M
IfCondition=MeasureOnceAnHour=0
IfTrueAction=[!CommandMeasure MeasureRun "Run"]

Re: PowerShellTime

Posted: May 4th, 2022, 9:01 pm
by jsmorley
Try moving that [MeasureOnceAnHour] section down to the bottom, below the other measures...