Skip to content

Instantly share code, notes, and snippets.

@o8r
Created April 16, 2021 07:19
Show Gist options
  • Select an option

  • Save o8r/f0ac03637bf5035c97e838748174fa5e to your computer and use it in GitHub Desktop.

Select an option

Save o8r/f0ac03637bf5035c97e838748174fa5e to your computer and use it in GitHub Desktop.
Show toast in Windows 10 using Powershell
<toast>
<visual>
<binding template="ToastGeneric">
<text>Toast was burnt</text>
<image placement="appLogOverride" src="C:\images\toaster.png"/>
</binding>
</visual>
<actions>
<input id="snoozeTime" type="selection" defaultInput="15">
<selection id="1" content="1 minute"/>
<selection id="15" content="15 minutes"/>
<selection id="60" content="1 hour"/>
<seloction id="240" content="4 hours"/>
<selection id="1440" content="1 day"/>
</input>
<action activationType="system" arguments="snooze" hint-inputId="snoozeTime" content=""/>
<action activationType="system" arguments="dismiss" content=""/>
</actions>
<audio silent="true"/>
</toast>
Param([string]$clsid, [string]$templateFile)
# Refer Windows Runtime
[Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime] > $null
[Windows.UI.Notifications.ToastNotification, Windows.UI.Notifications, ContentType = WindowsRuntime] > $null
# Read toast template XML
$template = Get-Content $templateFile
$xml = New-Object Windows.Data.Xml.Dom.XmlDocument
$xml.LoadXml($template)
#Toast notify
$app = $clsid
$toast = New-Object Windows.UI.Notifications.ToastNotification $xml
[Windows.UI.Notifications.ToastNotificationManager]:: CreateToastNotifier($app).Show($toast)
@o8r
Copy link
Author

o8r commented Apr 16, 2021

Usage

PS> .\win10toast.ps1 Microsoft.VisualStudioCode sample.xml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment