# EspansoEdit 1.4.5 Cookbook - 4.2 Powershell anchor scripts
# These scripts make use of YAML anchors and aliases
# The keywords anchors: and anchor: are arbitrary
# It is essential to use & to denote an anchor and * to reference an anchor
"d" { $date = (Get-Date).AddDays({{offset}}).ToString("dd/MM/yy") }
"w" { $date = (Get-Date).AddDays({{offset}} * 7).ToString("dd/MM/yy") }
"m" { $date = (Get-Date).AddMonths({{offset}}).ToString("dd/MM/yy") }
"y" { $date = (Get-Date).AddYears({{offset}}).ToString("dd/MM/yy") }
$e2 = 'C:\Users\Cam\AppData\Local\Programs\Espanso\espansod.exe'
&$e2 log | Out-File -FilePath $env:TEMP\tmp.log
$Array = Get-Content -Path $env:TEMP\tmp.log
$1..$Length | ForEach-Object {$Array[-$Line]; $Line++}
# Output last 10 lines of Espanso log
$Array = Get-Content -Path $env:LocalAppData\espanso\espanso.log -Tail 10
$1..$Length | ForEach-Object {$Array[-$Line]; $Line++}
# An anchor can be used to reference a file containing a PowerShell script
# Here the reference is to a script (not included) used to list installed apps
# Such a script (and more) can be found at https://github.com/fleschutz/PowerShell
& d:\temp\ps_listapps.ps1
# Conversion functions from https://github.com/NocTech/Temperature-Converter-PowerShell
function Convert-CelsiusToFahrenheit {
$fahrenheit = ($celsius * 9/5) + 32
function Convert-FahrenheitToCelsius {
$celsius = ($fahrenheit - 32) * 5/9
$f = Convert-CelsiusToFahrenheit -celsius $tmp
$f = [math]::Round($f, 2)
$c = Convert-FahrenheitToCelsius -fahrenheit $tmp
$c = [math]::Round($c, 2)
$result = switch ("{{unit}}") {
"c" {Write-Host $tmp{c =}$f{f}; break}
"f" {Write-Host $tmp{f =}$c{c}; break}
default {Write-Host "Correctly formatted entry not detected"; break} }
$filePath = "D:\temp\test.bat"
$stats = Get-Content $filePath | Measure-Object -Word -Line -Character
"Words: $($stats.Words); Lines: $($stats.Lines); Characters: $($stats.Characters)"
- regex: !datemath (?P<offset>[+-]\d+)(?P<unit>[dwmy])
# Run PowerShell script to perform date arithmetic
# Regex trigger responds to keyboard entries such as -70d or +12w
label: Date arithmetic with PowerShell
args: [C:\Program Files\PowerShell\7\pwsh.exe, -Command, *datemath]
- regex: !tempconv (?P<tmp>[+-]\d+)(?P<unit>[cf])
# Run PowerShell script to perform temperature conversion
# Regex trigger responds to keyboard entries such as -3c or +100f
label: Temperature conversion with PowerShell
args: [C:\Program Files\PowerShell\7\pwsh.exe, -Command, *tempconv]
# Use shell extension to get Espanso log forwards - latest at bottom
args: [C:\Program Files\PowerShell\7\pwsh.exe, -Command, *e2log]
# Run PowerShell script to get last 10 lines of Espanso log using shell extension
args: [C:\Program Files\PowerShell\7\pwsh.exe, -Command, *e2log10]
args: [C:\Program Files\PowerShell\7\pwsh.exe, -Command, *listapps]
args: [C:\Program Files\PowerShell\7\pwsh.exe, -Command, *quotestr]
args: [C:\Program Files\PowerShell\7\pwsh.exe, -Command, *wordcount]