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-13 10:52:55 +02:00
|
|
|
|
This script exports all PowerShell scripts to Serenade to execute them by voice.
|
|
|
|
|
.PARAMETER WakeWord
|
2021-11-21 12:21:34 +01:00
|
|
|
|
Specifies the wake word (none by default)
|
2021-10-13 10:52:55 +02:00
|
|
|
|
.PARAMETER FilePattern
|
|
|
|
|
Specifies the file pattern for the scripts ("$PSScriptRoot/*.ps1" by default)
|
2021-10-24 20:13:47 +02:00
|
|
|
|
.PARAMETER Application
|
|
|
|
|
Specifies the application to be used
|
2021-10-13 10:52:55 +02:00
|
|
|
|
.PARAMETER TargetFile
|
2021-11-21 12:21:34 +01:00
|
|
|
|
Specifies the target file ("$HOME\.serenade\scripts\PowerShell.js" by default)
|
2021-10-09 09:34:26 +02:00
|
|
|
|
.EXAMPLE
|
2021-10-13 10:52:55 +02:00
|
|
|
|
PS> ./export-to-serenade.ps1 Computer
|
2021-11-21 12:21:34 +01:00
|
|
|
|
⏳ Exporting 496 PowerShell scripts to C:\Users\Markus\.serenade\scripts\PowerShell.js...
|
|
|
|
|
✔️ exported 496 scripts with wake word "Computer" to Serenade in 3 sec
|
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-11-21 12:21:34 +01:00
|
|
|
|
param([string]$WakeWord = "", [string]$FilePattern = "$PSScriptRoot/*.ps1", [string]$Application = "terminal", [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"
|
2021-10-23 10:47:18 +02:00
|
|
|
|
"⏳ Found $($Scripts.Count) scripts, exporting them to $TargetFile..."
|
2021-10-10 09:46:38 +02:00
|
|
|
|
|
2021-10-13 10:52:55 +02:00
|
|
|
|
"/* NOTE: This file has been generated automatically by export-to-serenade.ps1 */" | Set-Content "$TargetFile"
|
2021-10-10 09:46:38 +02:00
|
|
|
|
foreach ($Script in $Scripts) {
|
|
|
|
|
$ScriptName = $Script.basename
|
2021-10-10 10:13:53 +02:00
|
|
|
|
$Keyword = $ScriptName -replace "-"," "
|
2021-10-24 20:13:47 +02:00
|
|
|
|
"serenade.global().command(`"$($WakeWord.toLower()) $Keyword`", async (api) => { await api.focusOrLaunchApplication(`"$Application`"); await api.typeText(`"$ScriptName.ps1`"); await api.pressKey(`"return`"); });" | Add-Content "$TargetFile"
|
2021-10-10 09:46:38 +02:00
|
|
|
|
}
|
2021-10-09 09:34:26 +02:00
|
|
|
|
|
2021-10-10 09:46:38 +02:00
|
|
|
|
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
|
2021-11-21 12:21:34 +01:00
|
|
|
|
"✔️ exported $($Scripts.Count) PowerShell scripts with wake word `"$WakeWord`" to Serenade in $Elapsed sec"
|
2021-10-10 09:46:38 +02:00
|
|
|
|
exit 0 # success
|
2021-10-09 09:34:26 +02:00
|
|
|
|
} catch {
|
|
|
|
|
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
|
|
|
|
exit 1
|
|
|
|
|
}
|