It is currently April 17th, 2021, 1:54 am

PowerShellTime

Clocks and timer skins
User avatar
jsmorley
Developer
Posts: 21635
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

PowerShellTime

Post 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()
You do not have the required permissions to view the files attached to this post.
User avatar
SilverAzide
Rainmeter Sage
Posts: 1218
Joined: March 23rd, 2015, 5:26 pm

Re: PowerShellTime

Post 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?
Gadgets Wiki GitHub More Gadgets...
User avatar
jsmorley
Developer
Posts: 21635
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: PowerShellTime

Post 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.
User avatar
jsmorley
Developer
Posts: 21635
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: PowerShellTime

Post 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...