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)
.EXAMPLE
PS> ./export-to-serenade.ps1 Computer
Exporting 264 scripts with wakeword 'Computer' to C:\Users\Markus/.serenade/scripts/custom.js...
exported 264 PowerShell scripts to Serenade in 22 sec
Exporting 264 PowerShell scripts to C:\Users\Markus/.serenade/scripts/custom.js...
exported 264 scripts with wakework "Computer" to Serenade in 22 sec
.NOTES
Author: Markus Fleschutz · License: CC0
.LINK
@ -27,20 +27,18 @@ try {
$StopWatch = [system.diagnostics.stopwatch]::startNew()
$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"
foreach ($Script in $Scripts) {
$ScriptName = $Script.basename
$Keyword = $ScriptName -replace "-"," "
"" | Add-Content "$TargetFile"
"serenade.global().command(`"$WakeWord $Keyword`", async (api) => {" | Add-Content "$TargetFile"
"await api.focusOrLaunchApplication(`"terminal`"); await api.typeText(`"$ScriptName.ps1`"); await api.pressKey(`"return`");" | Add-Content "$TargetFile"
"});" | 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"
}
[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
} catch {
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"