Skip to content

Instantly share code, notes, and snippets.

@vexx32
Forked from TylerLeonhardt/Invoke-PSNotification.ps1
Last active November 9, 2018 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vexx32/a3bd96434e152e9cfdf8390e50a03fec to your computer and use it in GitHub Desktop.
Save vexx32/a3bd96434e152e9cfdf8390e50a03fec to your computer and use it in GitHub Desktop.
Show notifications on Linux using PowerShell! Thanks to notify-send(1)
function Invoke-PSNotification {
[CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'Medium')]
param(
[Parameter(Position=0, Mandatory, ValueFromPipeline)]
[object[]]
$Body,
[string]
$Summary = 'PowerShell Notification',
[ValidateSet('Low', 'Normal', 'Critical')]
[string]
$Urgency,
[int]
$ExpireTime,
[string[]]
$Icon,
[ValidateSet(
"device","device.added","device.error","device.removed",
"email","email.arrived","email.bounced",
"im","im.error","im.received",
"network","network.connected","network.disconnected","network.error",
"presence","presence.offline","presence.online",
"transfer","transfer.complete","transfer.error" )]
[string[]]
$Category
)
begin {
$notifySendArgs = [System.Collections.Generic.List[psobject]]@()
if ($Urgency) {
$notifySendArgs.Add("--urgency=$Urgency")
}
if ($ExpireTime) {
$notifySendArgs.Add("--expire-time=$ExpireTime")
}
if ($Icon) {
$notifySendArgs.Add("--icon=$($Icon -join ',')")
}
if ($Catagory) {
$notifySendArgs.Add("--category=$($Category -join ',')")
}
$notifySendArgs.Add($Summary)
$notifySendArgs.Add("")
}
process {
$notifySendArgs[$notifySendArgs.Length - 1] = $Body
if ($PSCmdlet.ShouldProcess('notify-send', "$($notifySendArgs -join ' ')")) {
Start-Process -FilePath 'notify-send' -NoNewWindow -Wait -ArgumentList $notifySendArgs
}
}
end {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment