2021-10-09 09:34:26 +02:00
|
|
|
|
<#
|
|
|
|
|
.SYNOPSIS
|
2021-10-10 09:46:38 +02:00
|
|
|
|
Exports all scripts to Serenade for voice control
|
2021-10-09 09:34:26 +02:00
|
|
|
|
.DESCRIPTION
|
2021-10-10 09:46:38 +02:00
|
|
|
|
This script exports all PowerShell scripts to Serenade.ai for voice control.
|
2021-10-09 09:34:26 +02:00
|
|
|
|
.EXAMPLE
|
2021-10-10 09:46:38 +02:00
|
|
|
|
PS> ./export-scripts2serenade.ps1
|
2021-10-09 09:34:26 +02:00
|
|
|
|
.NOTES
|
2021-10-10 09:46:38 +02:00
|
|
|
|
Author: Markus Fleschutz · License: CC0
|
2021-10-09 09:34:26 +02:00
|
|
|
|
.LINK
|
2021-10-10 09:46:38 +02:00
|
|
|
|
https://github.com/fleschutz/PowerShell
|
2021-10-09 09:34:26 +02:00
|
|
|
|
#>
|
|
|
|
|
|
2021-10-10 09:46:38 +02:00
|
|
|
|
#requires -version 2
|
2021-10-09 09:34:26 +02:00
|
|
|
|
|
2021-10-10 09:46:38 +02:00
|
|
|
|
param([string]$FilePattern = "$PSScriptRoot/*.ps1", [string]$TargetFile = "$HOME/.serenade/scripts/PowerShell.js")
|
2021-10-09 09:34:26 +02:00
|
|
|
|
|
|
|
|
|
try {
|
2021-10-10 09:46:38 +02:00
|
|
|
|
$StopWatch = [system.diagnostics.stopwatch]::startNew()
|
|
|
|
|
|
|
|
|
|
$Scripts = Get-ChildItem "$FilePattern"
|
|
|
|
|
"Found $($Scripts.Count) scripts, starting export to $TargetFile..."
|
|
|
|
|
|
|
|
|
|
"/* Exported by export-scripts2serenade.ps1 */" > $TargetFile
|
|
|
|
|
foreach ($Script in $Scripts) {
|
|
|
|
|
$ScriptName = $Script.basename
|
|
|
|
|
"" >> $TargetFile
|
|
|
|
|
"serenade.global().command(\"$ScriptName\", async (api) => {" >> $TargetFile
|
|
|
|
|
"await api.focusOrLaunchApplication(\"terminal\");" >> $TargetFile
|
|
|
|
|
"await api.typeText(\"$Script\");" >> $TargetFile
|
|
|
|
|
"await api.pressKey(\"return\");" >> $TargetFile
|
|
|
|
|
"});" >> $TargetFile
|
|
|
|
|
}
|
2021-10-09 09:34:26 +02:00
|
|
|
|
|
2021-10-10 09:46:38 +02:00
|
|
|
|
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
|
|
|
|
|
"✔️ exported $($Scripts.Count) scripts to Serenade in $Elapsed sec"
|
|
|
|
|
exit 0 # success
|
2021-10-09 09:34:26 +02:00
|
|
|
|
} catch {
|
|
|
|
|
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
|
|
|
|
exit 1
|
|
|
|
|
}
|