2021-10-09 09:34:26 +02:00
|
|
|
|
<#
|
|
|
|
|
.SYNOPSIS
|
2021-11-30 10:34:53 +01:00
|
|
|
|
Exports scripts to Serenade
|
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-12-01 07:48:52 +01:00
|
|
|
|
⏳ Found 534 PowerShell scripts...
|
|
|
|
|
⏳ Writing custom JavaScript file: C:\Users\Markus\.serenade\scripts\PowerShell.js...
|
2021-11-29 07:59:13 +01:00
|
|
|
|
✔️ Exported to Serenade with wake word "Computer" 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-11-23 07:53:19 +01:00
|
|
|
|
"⏳ Found $($Scripts.Count) PowerShell scripts..."
|
2021-12-01 07:48:52 +01:00
|
|
|
|
"⏳ Writing custom JavaScript file: $TargetFile..."
|
2021-10-10 09:46:38 +02:00
|
|
|
|
|
2021-11-29 15:20:48 +01:00
|
|
|
|
"/* DO NOT EDIT! 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-12-11 17:44:30 +01:00
|
|
|
|
"serenade.global().command(`"$($WakeWord.toLower()) $Keyword`",async(api)=>{await api.focusApplication(`"$Application`");await api.pressKey(`"return`");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-29 07:59:13 +01:00
|
|
|
|
"✔️ Exported to Serenade with wake word `"$WakeWord`" 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
|
|
|
|
|
}
|