mirror of
https://github.com/fleschutz/PowerShell.git
synced 2024-12-25 08:09:17 +01:00
Update export-to-serenade.ps1
This commit is contained in:
parent
1c024ffb7c
commit
77fc5ad500
@ -8,10 +8,10 @@
|
|||||||
.PARAMETER FilePattern
|
.PARAMETER FilePattern
|
||||||
Specifies the file pattern for the scripts ("$PSScriptRoot/*.ps1" by default)
|
Specifies the file pattern for the scripts ("$PSScriptRoot/*.ps1" by default)
|
||||||
.PARAMETER TargetFile
|
.PARAMETER TargetFile
|
||||||
Specifies the target file ("$HOME/.serenade/scripts/custom.js" by default)
|
Specifies the target file ("$HOME/.serenade/scripts/PowerShell.js" by default)
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
PS> ./export-to-serenade.ps1 Computer
|
PS> ./export-to-serenade.ps1 Computer
|
||||||
⏳ Exporting 264 PowerShell scripts to C:\Users\Markus/.serenade/scripts/custom.js...
|
⏳ Exporting 264 PowerShell scripts to C:\Users\Markus/.serenade/scripts/PowerShell.js...
|
||||||
✔️ exported 264 scripts with wakework "Computer" 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
|
||||||
@ -21,24 +21,23 @@
|
|||||||
|
|
||||||
#requires -version 2
|
#requires -version 2
|
||||||
|
|
||||||
param([string]$WakeWord = "", [string]$FilePattern = "$PSScriptRoot/*.ps1", [string]$TargetFile = "$HOME/.serenade/scripts/custom.js")
|
param([string]$WakeWord = "", [string]$FilePattern = "$PSScriptRoot/*.ps1", [string]$TargetFile = "$HOME/.serenade/scripts/PowerShell.js")
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$StopWatch = [system.diagnostics.stopwatch]::startNew()
|
$StopWatch = [system.diagnostics.stopwatch]::startNew()
|
||||||
|
|
||||||
$Scripts = Get-ChildItem "$FilePattern"
|
$Scripts = Get-ChildItem "$FilePattern"
|
||||||
"⏳ Exporting $($Scripts.Count) PowerShell scripts to $TargetFile..."
|
"⏳ Found $($Scripts.Count) scripts, exporting them 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"
|
|
||||||
"serenade.global().command(`"$WakeWord $Keyword`", async (api) => { await api.focusOrLaunchApplication(`"terminal`"); await api.typeText(`"$ScriptName.ps1`"); await api.pressKey(`"return`"); });" | 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
|
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
|
||||||
"✔️ exported $($Scripts.Count) scripts with wakeword `"$WakeWord`" to Serenade in $Elapsed sec"
|
"✔️ exported $($Scripts.Count) PowerShell 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])"
|
||||||
|
Loading…
Reference in New Issue
Block a user