It is currently June 29th, 2022, 3:21 pm

PowerShellTime

Clocks and timer skins
User avatar
jsmorley
Developer
Posts: 22526
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: 1914
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: 22526
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: 22526
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...
TomShadow55
Posts: 4
Joined: May 4th, 2022, 12:11 pm

Re: PowerShellTime

Post by TomShadow55 »

hello, I would like to know if it is possible to add a command so that the SpeakTime is activated every hour?
User avatar
jsmorley
Developer
Posts: 22526
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: PowerShellTime

Post 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"]
TomShadow55
Posts: 4
Joined: May 4th, 2022, 12:11 pm

Re: PowerShellTime

Post by TomShadow55 »

jsmorley wrote: May 4th, 2022, 12:34 pm Just add this measure to the skin:

Code: Select all

[MeasureOnceAnHour]
Measure=Time
Format=%#M
IfCondition=MeasureOnceAnHour=0
IfTrueAction=[!CommandMeasure MeasureRun "Run"]
thank you very much, I am a new Rainmeter user and your skin is the first one I try to set.
TomShadow55
Posts: 4
Joined: May 4th, 2022, 12:11 pm

Re: PowerShellTime

Post by TomShadow55 »

it works but I don't understand why the voice says 4:59 and not 5 o'clock?
I made some modifications I put the code here so that you can check if there is not a bad command.
On the other hand for your [MeasureOnceAnHour] you use
Format=%#M if I understand correctly it is a calculation base on 60 min? isn't that why the voice command is triggered with a one-minute delay?

Code: Select all

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

[Variables]
Voice=female
;Voice=male

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

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

[MeterCMD]
Meter=String
MeasureName=MeasureCMD
FontSize=20
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1

[MeasureTime]
Measure=Time
Format=%#HH%M %A %#d %B %Y 
FormatLocale=Local


[MeasureSpeakTime]
Measure=Time
Format=il est %#H heure %M 
RegExpSubStitute=1
Substitute="(?siU)(\w)(\w).$":"\1 \2"
FormatLocale=Local

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

[MeterTime]
Meter=String
MeasureName=MeasureTime
FontSize=20
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
DynamicVariables=1

User avatar
jsmorley
Developer
Posts: 22526
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: PowerShellTime

Post by jsmorley »

Try moving that [MeasureOnceAnHour] section down to the bottom, below the other measures...
TomShadow55
Posts: 4
Joined: May 4th, 2022, 12:11 pm

Re: PowerShellTime

Post by TomShadow55 »

it got fixed.
it is possible to configure several commands? example at 11 a.m. it says "it's 11 a.m. take your medicine"
and is it possible to create a command that activates on click and that would give the full time and date?
I tried with LeftMouseClickAction=[!CommandMeasure MeasureRun "Run"] but it doesn't work