Update export-to-serenade.ps1

This commit is contained in:
Markus Fleschutz 2021-10-21 17:15:48 +02:00
parent 15229dfe3a
commit 352afcc3c4

View File

@ -11,8 +11,8 @@
Specifies the target file ("$HOME/.serenade/scripts/custom.js" by default) Specifies the target file ("$HOME/.serenade/scripts/custom.js" by default)
.EXAMPLE .EXAMPLE
PS> ./export-to-serenade.ps1 Computer PS> ./export-to-serenade.ps1 Computer
Exporting 264 scripts with wakeword 'Computer' to C:\Users\Markus/.serenade/scripts/custom.js... Exporting 264 PowerShell scripts to C:\Users\Markus/.serenade/scripts/custom.js...
exported 264 PowerShell scripts to Serenade in 22 sec exported 264 scripts with wakework "Computer" to Serenade in 22 sec
.NOTES .NOTES
Author: Markus Fleschutz · License: CC0 Author: Markus Fleschutz · License: CC0
.LINK .LINK
@ -27,20 +27,18 @@ try {
$StopWatch = [system.diagnostics.stopwatch]::startNew() $StopWatch = [system.diagnostics.stopwatch]::startNew()
$Scripts = Get-ChildItem "$FilePattern" $Scripts = Get-ChildItem "$FilePattern"
"⏳ Exporting $($Scripts.Count) scripts with wakeword `"$WakeWord`" to $TargetFile..." "⏳ Exporting $($Scripts.Count) PowerShell scripts to $TargetFile..."
"/* NOTE: This file has been generated automatically by export-to-serenade.ps1 */" | Set-Content "$TargetFile" "/* NOTE: This file has been generated automatically by export-to-serenade.ps1 */" | Set-Content "$TargetFile"
foreach ($Script in $Scripts) { foreach ($Script in $Scripts) {
$ScriptName = $Script.basename $ScriptName = $Script.basename
$Keyword = $ScriptName -replace "-"," " $Keyword = $ScriptName -replace "-"," "
"" | Add-Content "$TargetFile" "" | Add-Content "$TargetFile"
"serenade.global().command(`"$WakeWord $Keyword`", async (api) => {" | Add-Content "$TargetFile" "serenade.global().command(`"$WakeWord $Keyword`", async (api) => { await api.focusOrLaunchApplication(`"terminal`"); await api.typeText(`"$ScriptName.ps1`"); await api.pressKey(`"return`"); });" | Add-Content "$TargetFile"
"await api.focusOrLaunchApplication(`"terminal`"); await api.typeText(`"$ScriptName.ps1`"); await api.pressKey(`"return`");" | Add-Content "$TargetFile"
"});" | Add-Content "$TargetFile"
} }
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds [int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
"✔️ exported $($Scripts.Count) PowerShell scripts to Serenade in $Elapsed sec" "✔️ exported $($Scripts.Count) scripts with wakeword `"$WakeWord`" to Serenade in $Elapsed sec"
exit 0 # success exit 0 # success
} catch { } catch {
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"