コピペするだけで使えます。BurntToastが管理者権限でインストールできない場合やよりカスタマイズしたい場合にご活用ください。
PowerShell 7.1以降をお使いの方へ
WinRT.Runtime.dll
とMicrosoft.Windows.SDK.NET.dll
をロードし、完全修飾名を削除する必要があります。
例:
Invoke-WebRequest https://github.com/Windos/BurntToast/raw/main/BurntToast/lib/Microsoft.Windows.SDK.NET/WinRT.Runtime.dll -OutFile WinRT.Runtime.dll
Add-Type -Path WinRT.Runtime.dll
Invoke-WebRequest https://github.com/Windos/BurntToast/raw/main/BurntToast/lib/Microsoft.Windows.SDK.NET/Microsoft.Windows.SDK.NET.dll -OutFile Microsoft.Windows.SDK.NET.dll
Add-Type -Path Microsoft.Windows.SDK.NET.dll
$xml = @"
<toast>
<visual>
<binding template="ToastGeneric">
<text>Hello World</text>
<text>This is a simple toast message</text>
</binding>
</visual>
</toast>
"@
$XmlDocument = [Windows.Data.Xml.Dom.XmlDocument]::New()
$XmlDocument.loadXml($xml)
[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier().Show($XmlDocument)
以下でWinRT.Runtime.dll
とMicrosoft.Windows.SDK.NET.dll
をロードすることもできます。管理者権限が必要かもしれませんが。
Find-Package -ProviderName NuGet -Source https://www.nuget.org/api/v2 -Name Microsoft.Windows.SDK.NET.Ref | Install-Package
Add-Type -Path $env:ProgramFiles/PackageManagement/NuGet/Packages/Microsoft.Windows.SDK.NET.Ref.*/lib/net*/*.dll
https://github.com/PowerShell/PowerShell/issues/13042#issuecomment-653357546
1行テキスト
$bodyText = 'A single string wrapped across a maximum of three lines of text.'
$ToastText01 = [Windows.UI.Notifications.ToastTemplateType, Windows.UI.Notifications, ContentType = WindowsRuntime]::ToastText01
$TemplateContent = [Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime]::GetTemplateContent($ToastText01)
$TemplateContent.SelectSingleNode('//text[@id="1"]').InnerText = $bodyText
$AppId = '{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\WindowsPowerShell\v1.0\powershell.exe'
[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($AppId).Show($TemplateContent)
2行テキスト
$headlineText = 'One string of bold text on the first line.'
$bodyText = 'One string of regular text wrapped across the second and third lines.'
$ToastText02 = [Windows.UI.Notifications.ToastTemplateType, Windows.UI.Notifications, ContentType = WindowsRuntime]::ToastText02
$TemplateContent = [Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime]::GetTemplateContent($ToastText02)
$TemplateContent.SelectSingleNode('//text[@id="1"]').InnerText = $headlineText
$TemplateContent.SelectSingleNode('//text[@id="2"]').InnerText = $bodyText
$AppId = '{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\WindowsPowerShell\v1.0\powershell.exe'
[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($AppId).Show($TemplateContent)
2行テキスト折り返し
$headlineText = 'One string of bold text wrapped across the first and second lines.'
$bodyText = 'One string of regular text on the third line.'
$ToastText03 = [Windows.UI.Notifications.ToastTemplateType, Windows.UI.Notifications, ContentType = WindowsRuntime]::ToastText03
$TemplateContent = [Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime]::GetTemplateContent($ToastText03)
$TemplateContent.SelectSingleNode('//text[@id="1"]').InnerText = $headlineText
$TemplateContent.SelectSingleNode('//text[@id="2"]').InnerText = $bodyText
$AppId = '{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\WindowsPowerShell\v1.0\powershell.exe'
[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($AppId).Show($TemplateContent)
3行テキスト
$headlineText = 'One string of bold text on the first line.'
$bodyText1 = 'One string of regular text on the second line.'
$bodyText2 = 'One string of regular text on the third line.'
$ToastText04 = [Windows.UI.Notifications.ToastTemplateType, Windows.UI.Notifications, ContentType = WindowsRuntime]::ToastText04
$TemplateContent = [Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime]::GetTemplateContent($ToastText04)
$TemplateContent.SelectSingleNode('//text[@id="1"]').InnerText = $headlineText
$TemplateContent.SelectSingleNode('//text[@id="2"]').InnerText = $bodyText1
$TemplateContent.SelectSingleNode('//text[@id="3"]').InnerText = $bodyText2
$AppId = '{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\WindowsPowerShell\v1.0\powershell.exe'
[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($AppId).Show($TemplateContent)
1行テキストと画像
$image = 'C:\Windows\IdentityCRL\WLive48x48.png'
$bodyText = 'A single string wrapped across a maximum of three lines of text.'
$ToastImageAndText01 = [Windows.UI.Notifications.ToastTemplateType, Windows.UI.Notifications, ContentType = WindowsRuntime]::ToastImageAndText01
$TemplateContent = [Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime]::GetTemplateContent($ToastImageAndText01)
$TemplateContent.SelectSingleNode('//image[@id="1"]').SetAttribute('src', $image)
$TemplateContent.SelectSingleNode('//text[@id="1"]').InnerText = $bodyText
$AppId = '{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\WindowsPowerShell\v1.0\powershell.exe'
[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($AppId).Show($TemplateContent)
2行テキストと画像
$image = 'C:\Windows\IdentityCRL\WLive48x48.png'
$headlineText = 'One string of bold text on the first line.'
$bodyText = 'One string of regular text wrapped across the second and third lines.'
$ToastImageAndText02 = [Windows.UI.Notifications.ToastTemplateType, Windows.UI.Notifications, ContentType = WindowsRuntime]::ToastImageAndText02
$TemplateContent = [Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime]::GetTemplateContent($ToastImageAndText02)
$TemplateContent.SelectSingleNode('//image[@id="1"]').SetAttribute('src', $image)
$TemplateContent.SelectSingleNode('//text[@id="1"]').InnerText = $headlineText
$TemplateContent.SelectSingleNode('//text[@id="2"]').InnerText = $bodyText
$AppId = '{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\WindowsPowerShell\v1.0\powershell.exe'
[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($AppId).Show($TemplateContent)
2行テキスト折り返しと画像
$image = 'C:\Windows\IdentityCRL\WLive48x48.png'
$headlineText = 'One string of bold text wrapped across the first two lines.'
$bodyText = 'One string of regular text on the third line.'
$ToastImageAndText03 = [Windows.UI.Notifications.ToastTemplateType, Windows.UI.Notifications, ContentType = WindowsRuntime]::ToastImageAndText03
$TemplateContent = [Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime]::GetTemplateContent($ToastImageAndText03)
$TemplateContent.SelectSingleNode('//image[@id="1"]').SetAttribute('src', $image)
$TemplateContent.SelectSingleNode('//text[@id="1"]').InnerText = $headlineText
$TemplateContent.SelectSingleNode('//text[@id="2"]').InnerText = $bodyText
$AppId = '{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\WindowsPowerShell\v1.0\powershell.exe'
[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($AppId).Show($TemplateContent)
3行テキストと画像
$image = 'C:\Windows\IdentityCRL\WLive48x48.png'
$headlineText = 'One string of bold text on the first line.'
$bodyText1 = 'One string of regular text on the second line.'
$bodyText2 = 'One string of regular text on the third line.'
$ToastImageAndText04 = [Windows.UI.Notifications.ToastTemplateType, Windows.UI.Notifications, ContentType = WindowsRuntime]::ToastImageAndText04
$TemplateContent = [Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime]::GetTemplateContent($ToastImageAndText04)
$TemplateContent.SelectSingleNode('//image[@id="1"]').SetAttribute('src', $image)
$TemplateContent.SelectSingleNode('//text[@id="1"]').InnerText = $headlineText
$TemplateContent.SelectSingleNode('//text[@id="2"]').InnerText = $bodyText1
$TemplateContent.SelectSingleNode('//text[@id="3"]').InnerText = $bodyText2
$AppId = '{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\WindowsPowerShell\v1.0\powershell.exe'
[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($AppId).Show($TemplateContent)
改行 `n
$bodyText = "ASCII.JP`nWindows Info"
$ToastText01 = [Windows.UI.Notifications.ToastTemplateType, Windows.UI.Notifications, ContentType = WindowsRuntime]::ToastText01
$TemplateContent = [Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime]::GetTemplateContent($ToastText01)
$TemplateContent.SelectSingleNode('//text[@id="1"]').InnerText = $bodyText
$AppId = '{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\WindowsPowerShell\v1.0\powershell.exe'
[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($AppId).Show($TemplateContent)
ロゴ画像 placement="appLogoOverride"
$headlineText = 'One string of bold text on the first line.'
$bodyText = 'One string of regular text on the second line.'
$logo = 'C:\Windows\IdentityCRL\WLive48x48.png'
$image = 'C:\Windows\Web\Screen\img100.jpg'
$xml = @"
<toast>
<visual>
<binding template="ToastGeneric">
<text>$($headlineText)</text>
<text>$($bodyText)</text>
<image placement="appLogoOverride" src="$($logo)"/>
<image src="$($image)"/>
</binding>
</visual>
</toast>
"@
$XmlDocument = [Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime]::New()
$XmlDocument.loadXml($xml)
$AppId = '{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\WindowsPowerShell\v1.0\powershell.exe'
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime]::CreateToastNotifier($AppId).Show($XmlDocument)
丸いロゴ hint-crop="circle"
$headlineText = 'One string of bold text on the first line.'
$bodyText = 'One string of regular text on the second line.'
$logo = 'C:\Windows\IdentityCRL\WLive48x48.png'
$image = 'C:\Windows\Web\Screen\img100.jpg'
$xml = @"
<toast>
<visual>
<binding template="ToastGeneric">
<text>$($headlineText)</text>
<text>$($bodyText)</text>
<image placement="appLogoOverride" hint-crop="circle" src="$($logo)"/>
<image src="$($image)"/>
</binding>
</visual>
</toast>
"@
$XmlDocument = [Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime]::New()
$XmlDocument.loadXml($xml)
$AppId = '{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\WindowsPowerShell\v1.0\powershell.exe'
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime]::CreateToastNotifier($AppId).Show($XmlDocument)
上部に画像 placement="hero"
$headlineText = 'One string of bold text on the first line.'
$bodyText = 'One string of regular text on the second line.'
$logo = 'C:\Windows\IdentityCRL\WLive48x48.png'
$image = 'C:\Windows\Web\Screen\img100.jpg'
$xml = @"
<toast>
<visual>
<binding template="ToastGeneric">
<text>$($headlineText)</text>
<text>$($bodyText)</text>
<image placement="appLogoOverride" src="$($logo)"/>
<image placement="hero" src="$($image)"/>
</binding>
</visual>
</toast>
"@
$XmlDocument = [Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime]::New()
$XmlDocument.loadXml($xml)
$AppId = '{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\WindowsPowerShell\v1.0\powershell.exe'
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime]::CreateToastNotifier($AppId).Show($XmlDocument)
基本
$xml = @"
<toast>
<visual>
<binding template="ToastGeneric">
<text>Hello World</text>
<text>This is a simple toast message</text>
</binding>
</visual>
</toast>
"@
$XmlDocument = [Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime]::New()
$XmlDocument.loadXml($xml)
$AppId = '{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\WindowsPowerShell\v1.0\powershell.exe'
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime]::CreateToastNotifier($AppId).Show($XmlDocument)
音
$xml = @"
<toast>
<visual>
<binding template="ToastGeneric">
<text>Hello World</text>
<text>This is a simple toast message</text>
</binding>
</visual>
<audio src="ms-winsoundevent:Notification.Reminder"/>
</toast>
"@
$XmlDocument = [Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime]::New()
$XmlDocument.loadXml($xml)
$AppId = '{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\WindowsPowerShell\v1.0\powershell.exe'
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime]::CreateToastNotifier($AppId).Show($XmlDocument)
利用可能な音一覧
https://docs.microsoft.com/en-us/uwp/schemas/tiles/toastschema/element-audio#attributes
音のループ
$xml = @"
<toast>
<visual>
<binding template="ToastGeneric">
<text>Hello World</text>
<text>This is a simple toast message</text>
</binding>
</visual>
<audio src="ms-winsoundevent:Notification.Reminder" loop="true"/>
</toast>
"@
$XmlDocument = [Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime]::New()
$XmlDocument.loadXml($xml)
$AppId = '{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\WindowsPowerShell\v1.0\powershell.exe'
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime]::CreateToastNotifier($AppId).Show($XmlDocument)
無音
$xml = @"
<toast>
<visual>
<binding template="ToastGeneric">
<text>Hello World</text>
<text>This is a simple toast message</text>
</binding>
</visual>
<audio silent="true"/>
</toast>
"@
$XmlDocument = [Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime]::New()
$XmlDocument.loadXml($xml)
$AppId = '{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\WindowsPowerShell\v1.0\powershell.exe'
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime]::CreateToastNotifier($AppId).Show($XmlDocument)
URLを設定して音を鳴らす
$xml = @"
<toast>
<visual>
<binding template="ToastGeneric">
<text>Hello World</text>
<text>This is a simple toast message</text>
</binding>
</visual>
<audio silent="true"/>
</toast>
"@
$XmlDocument = [Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime]::New()
$XmlDocument.loadXml($xml)
$AppId = '{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\WindowsPowerShell\v1.0\powershell.exe'
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime]::CreateToastNotifier($AppId).Show($XmlDocument)
$MediaPlayer = [Windows.Media.Playback.MediaPlayer, Windows.Media, ContentType = WindowsRuntime]::New()
$MediaPlayer.Source = [Windows.Media.Core.MediaSource]::CreateFromUri('https://nyanpass.com/nyanpass.mp3')
$MediaPlayer.Play()
ファイルを設定して音を鳴らす
$xml = @"
<toast>
<visual>
<binding template="ToastGeneric">
<text>Hello World</text>
<text>This is a simple toast message</text>
</binding>
</visual>
<audio silent="true"/>
</toast>
"@
$XmlDocument = [Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime]::New()
$XmlDocument.loadXml($xml)
$AppId = '{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\WindowsPowerShell\v1.0\powershell.exe'
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime]::CreateToastNotifier($AppId).Show($XmlDocument)
$MediaPlayer = [Windows.Media.Playback.MediaPlayer, Windows.Media, ContentType = WindowsRuntime]::New()
$MediaPlayer.Source = [Windows.Media.Core.MediaSource]::CreateFromUri('C:\Users\Admin\Downloads\nyanpass.mp3')
$MediaPlayer.Play()
テキスト読み上げ
$xml = @"
<toast>
<visual>
<binding template="ToastGeneric">
<text>Hello World</text>
<text>This is a simple toast message</text>
</binding>
</visual>
<audio silent="true"/>
</toast>
"@
$XmlDocument = [Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime]::New()
$XmlDocument.loadXml($xml)
$AppId = '{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\WindowsPowerShell\v1.0\powershell.exe'
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime]::CreateToastNotifier($AppId).Show($XmlDocument)
Add-Type -AssemblyName System.speech
([System.Speech.Synthesis.SpeechSynthesizer]::New()).Speak('Hello world')
リンクを開く
$xml = @"
<toast activationType="protocol" launch="https://www.google.com/" >
<visual>
<binding template="ToastGeneric">
<text>Click to open Google</text>
</binding>
</visual>
</toast>
"@
$XmlDocument = [Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime]::New()
$XmlDocument.loadXml($xml)
$AppId = '{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\WindowsPowerShell\v1.0\powershell.exe'
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime]::CreateToastNotifier($AppId).Show($XmlDocument)
ボタンをクリックしてリンクを開く
$xml = @"
<toast>
<visual>
<binding template="ToastGeneric">
<text>Hello World</text>
<text>This is a simple toast message</text>
</binding>
</visual>
<actions>
<action content="Open Google" activationType="protocol" arguments="https://www.google.com/" />
</actions>
</toast>
"@
$XmlDocument = [Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime]::New()
$XmlDocument.loadXml($xml)
$AppId = '{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\WindowsPowerShell\v1.0\powershell.exe'
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime]::CreateToastNotifier($AppId).Show($XmlDocument)
Pythonスクリプトを実行
$PSDefaultParameterValues['Out-File:Encoding'] = 'utf8'
'import webbrowser; webbrowser.open("https://www.python.org")' > handler.pyw
$xml = @"
<toast>
<visual>
<binding template="ToastGeneric">
<text>Hello World</text>
<text>This is a simple toast message</text>
</binding>
</visual>
<actions>
<action content="Execute Python Script" activationType="protocol" arguments="$($PWD)\handler.pyw" />
</actions>
</toast>
"@
$XmlDocument = [Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime]::New()
$XmlDocument.loadXml($xml)
$AppId = '{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\WindowsPowerShell\v1.0\powershell.exe'
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime]::CreateToastNotifier($AppId).Show($XmlDocument)
長く表示される通知
$xml = @"
<toast duration="long">
<visual>
<binding template="ToastGeneric">
<text>Hello World</text>
<text>This is a simple toast message</text>
</binding>
</visual>
</toast>
"@
$XmlDocument = [Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime]::New()
$XmlDocument.loadXml($xml)
$AppId = '{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\WindowsPowerShell\v1.0\powershell.exe'
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime]::CreateToastNotifier($AppId).Show($XmlDocument)
25秒表示されます
通知を永遠に表示する(タイムアウトなし) scenario="incomingCall"
$xml = @"
<toast scenario="incomingCall">
<visual>
<binding template="ToastGeneric">
<text>Hello World</text>
<text>This is a simple toast message</text>
</binding>
</visual>
</toast>
"@
$XmlDocument = [Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime]::New()
$XmlDocument.loadXml($xml)
$AppId = '{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\WindowsPowerShell\v1.0\powershell.exe'
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime]::CreateToastNotifier($AppId).Show($XmlDocument)
alarm, reminder, incomingCall, urgentも設定可能
アラーム scenario="alarm"
$xml = @"
<toast launch="action=viewAlarm&alarmId=3" scenario="alarm">
<visual>
<binding template="ToastGeneric">
<text>Time to wake up!</text>
<text>To prove you're awake, select which of the following fruits is yellow...</text>
</binding>
</visual>
<actions>
<input id="answer" type="selection" defaultInput="wrongDefault">
<selection id="wrong" content="Orange"/>
<selection id="wrongDefault" content="Blueberry"/>
<selection id="right" content="Banana"/>
<selection id="wrong" content="Avacado"/>
<selection id="wrong" content="Cherry"/>
</input>
<action
activationType="system"
arguments="snooze"
content=""/>
<action
activationType="background"
arguments="dismiss"
content="Dismiss"/>
</actions>
</toast>
"@
$XmlDocument = [Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime]::New()
$XmlDocument.loadXml($xml)
$AppId = '{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\WindowsPowerShell\v1.0\powershell.exe'
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime]::CreateToastNotifier($AppId).Show($XmlDocument)
スヌーズできます。
ニュース速報 placement="attribution"
$xml = @"
<toast launch="action=viewStory&storyId=92187">
<visual>
<binding template="ToastGeneric">
<text>Tortoise beats rabbit in epic race</text>
<text>In a surprising turn of events, Rockstar Rabbit took a nasty crash, allowing Thomas the Tortoise to win the race.</text>
<text placement="attribution">The Animal Times</text>
</binding>
</visual>
</toast>
"@
$XmlDocument = [Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime]::New()
$XmlDocument.loadXml($xml)
$AppId = '{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\WindowsPowerShell\v1.0\powershell.exe'
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime]::CreateToastNotifier($AppId).Show($XmlDocument)
イベントに招待
$xml = @"
<toast launch="action=viewEvent&eventId=63851">
<visual>
<binding template="ToastGeneric">
<text>Surface Launch Party</text>
<text>Studio S / Ballroom</text>
<text>4:00 PM, 10/26/2015</text>
</binding>
</visual>
<actions>
<input id="status" type="selection" defaultInput="yes">
<selection id="yes" content="Going"/>
<selection id="maybe" content="Maybe"/>
<selection id="no" content="Decline"/>
</input>
<action
activationType="background"
arguments="action=rsvpEvent&eventId=63851"
content="RSVP"/>
<action
activationType="system"
arguments="dismiss"
content=""/>
</actions>
</toast>
"@
$XmlDocument = [Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime]::New()
$XmlDocument.loadXml($xml)
$AppId = '{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\WindowsPowerShell\v1.0\powershell.exe'
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime]::CreateToastNotifier($AppId).Show($XmlDocument)
フレンド申請
$xml = @"
<toast launch="action=viewFriendRequest&userId=49183">
<visual>
<binding template="ToastGeneric">
<text>Matt sent you a friend request</text>
<text>Hey, wanna dress up as wizards and ride around on our hoverboards together?</text>
<image placement="appLogoOverride" hint-crop="circle" src="C:\Windows\IdentityCRL\WLive48x48.png"/>
</binding>
</visual>
<actions>
<action content="Accept" activationType="background" arguments="action=acceptFriendRequest&userId=49183"/>
<action content="Decline" activationType="background" arguments="action=declineFriendRequest&userId=49183"/>
</actions>
</toast>
"@
$XmlDocument = [Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime]::New()
$XmlDocument.loadXml($xml)
$AppId = '{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\WindowsPowerShell\v1.0\powershell.exe'
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime]::CreateToastNotifier($AppId).Show($XmlDocument)
着信 scenario="incomingCall"
$xml = @"
<toast launch="action=answer&callId=938163" scenario="incomingCall">
<visual>
<binding template="ToastGeneric">
<text>Andrew Bares</text>
<text>Incoming Call - Mobile</text>
<image hint-crop="circle" src="https://unsplash.it/100?image=883"/>
</binding>
</visual>
<actions>
<action
content="Text reply"
imageUri="https://storage.googleapis.com/rppico.appspot.com/message.png"
activationType="foreground"
arguments="action=textReply&callId=938163"/>
<action
content="Reminder"
imageUri="https://storage.googleapis.com/rppico.appspot.com/reminder.png"
activationType="background"
arguments="action=reminder&callId=938163"/>
<action
content="Ignore"
imageUri="https://storage.googleapis.com/rppico.appspot.com/cancel.png"
activationType="background"
arguments="action=ignore&callId=938163"/>
<action
content="Answer"
imageUri="https://storage.googleapis.com/rppico.appspot.com/telephone.png"
arguments="action=answer&callId=938163"/>
</actions>
</toast>
"@
$XmlDocument = [Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime]::New()
$XmlDocument.loadXml($xml)
$AppId = 'Microsoft.WindowsTerminal_8wekyb3d8bbwe!App'
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime]::CreateToastNotifier($AppId).Show($XmlDocument)
メッセージ
$xml = @"
<toast launch="action=openThread&threadId=92187">
<visual>
<binding template="ToastGeneric">
<text hint-maxLines="1">Jill Bender</text>
<text>Check out where we camped last weekend! It was incredible, wish you could have come on the backpacking trip!</text>
<image placement="appLogoOverride" hint-crop="circle" src="https://unsplash.it/64?image=1027"/>
<image placement="hero" src="https://unsplash.it/360/180?image=1043"/>
</binding>
</visual>
<actions>
<input id="textBox" type="text" placeHolderContent="reply"/>
<action
content="Send"
imageUri="https://storage.googleapis.com/rppico.appspot.com/send.png"
hint-inputId="textBox"
activationType="background"
arguments="action=reply&threadId=92187"/>
</actions>
</toast>
"@
$XmlDocument = [Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime]::New()
$XmlDocument.loadXml($xml)
$AppId = 'Microsoft.WindowsTerminal_8wekyb3d8bbwe!App'
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime]::CreateToastNotifier($AppId).Show($XmlDocument)
タグ付けされた写真
$xml = @"
<toast launch="action=viewPhoto&photoId=92187">
<visual>
<binding template="ToastGeneric">
<image placement="appLogoOverride" hint-crop="circle" src="https://unsplash.it/64?image=669"/>
<text>Adam Wilson tagged you in a photo</text>
<text>On top of McClellan Butte - with Andrew Bares</text>
<image src="https://unsplash.it/360/202?image=883"/>
</binding>
</visual>
<actions>
<action
content="Like"
activationType="background"
arguments="likePhoto&photoId=92187"/>
<action
content="Comment"
arguments="action=commentPhoto&photoId=92187"/>
</actions>
</toast>
"@
$XmlDocument = [Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime]::New()
$XmlDocument.loadXml($xml)
$AppId = 'Microsoft.WindowsTerminal_8wekyb3d8bbwe!App'
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime]::CreateToastNotifier($AppId).Show($XmlDocument)
進捗バー
$xml = @"
<toast launch="action=viewDownload&downloadId=9438108">
<visual>
<binding template="ToastGeneric">
<text>Downloading this week's new video...</text>
<progress
title="{progressTitle}"
value="{progressValue}"
valueStringOverride="{progressValueString}"
status="{progressStatus}"/>
</binding>
</visual>
<actions>
<action
activationType="background"
arguments="action=pauseDownload&downloadId=9438108"
content="Pause"/>
<action
activationType="background"
arguments="action=cancelDownload&downloadId=9438108"
content="Cancel"/>
</actions>
</toast>
"@
$XmlDocument = [Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime]::New()
$XmlDocument.loadXml($xml)
$ToastNotification = [Windows.UI.Notifications.ToastNotification, Windows.UI.Notifications, ContentType = WindowsRuntime]::New($XmlDocument)
$ToastNotification.Tag = 'my_tag'
$Dictionary = [System.Collections.Generic.Dictionary[String, String]]::New()
$Dictionary.Add('progressTitle', 'YouTube')
$Dictionary.Add('progressValue', '0')
$Dictionary.Add('progressValueString', '0/15 videos')
$Dictionary.Add('progressStatus', 'Downloading...')
$ToastNotification.Data = [Windows.UI.Notifications.NotificationData]::New($Dictionary)
$ToastNotification.Data.SequenceNumber = 1
$AppId = '{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\WindowsPowerShell\v1.0\powershell.exe'
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime]::CreateToastNotifier($AppId).Show($ToastNotification)
for ($index = 1; $index -le 15; $index++) {
Start-Sleep 1
$Dictionary = [System.Collections.Generic.Dictionary[String, String]]::New()
$Dictionary.Add('progressValue', $index / 15)
$Dictionary.Add('progressValueString', "$index/15 videos")
$NotificationData = [Windows.UI.Notifications.NotificationData]::New($Dictionary)
$NotificationData.SequenceNumber = 2
[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($AppId).Update($NotificationData, 'my_tag')
}
$Dictionary = [System.Collections.Generic.Dictionary[String, String]]::New()
$Dictionary.Add('progressStatus', 'Completed!')
$NotificationData = [Windows.UI.Notifications.NotificationData]::New($Dictionary)
$NotificationData.SequenceNumber = 2
[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($AppId).Update($NotificationData, 'my_tag')
リマインダー scenario="reminder"
$xml = @"
<toast launch="action=viewEvent&eventId=1983" scenario="reminder">
<visual>
<binding template="ToastGeneric">
<text>Adaptive Tiles Meeting</text>
<text>Conf Room 2001 / Building 135</text>
<text>10:00 AM - 10:30 AM</text>
</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"/>
<selection 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>
</toast>
"@
$XmlDocument = [Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime]::New()
$XmlDocument.loadXml($xml)
$AppId = '{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\WindowsPowerShell\v1.0\powershell.exe'
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime]::CreateToastNotifier($AppId).Show($XmlDocument)
通知が再度表示されます。
レストラン
$xml = @"
<toast launch="action=viewRestaurant&restaurantId=92187">
<visual>
<binding template="ToastGeneric">
<image placement="hero" src="https://storage.googleapis.com/rppico.appspot.com/Food1.jpg"/>
<text hint-maxLines="1">New suggested restaurant</text>
<text>There's a popular chinese restaurant near you that we think you'd like!</text>
<image src="https://storage.googleapis.com/rppico.appspot.com/RestaurantMap.jpg"/>
<group>
<subgroup>
<text hint-style="body">Pho Licious</text>
<text hint-style="captionSubtle">4.6 stars</text>
</subgroup>
<subgroup hint-textStacking="bottom">
<text hint-style="captionSubtle" hint-wrap="true" hint-align="right">4018 148th Ave NE, Redmond, WA 98052</text>
</subgroup>
</group>
</binding>
</visual>
<actions>
<action
content="Map"
arguments="bingmaps:?q=4018 148th Ave NE, Redmond, WA 98052"
activationType="protocol"/>
<action
content="Reviews"
arguments="action=viewRestaurantReviews&restaurantId=92187"/>
</actions>
</toast>
"@
$XmlDocument = [Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime]::New()
$XmlDocument.loadXml($xml)
$AppId = 'Microsoft.WindowsTerminal_8wekyb3d8bbwe!App'
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime]::CreateToastNotifier($AppId).Show($XmlDocument)
2カラムデザインにできます。
天気
$xml = @"
<toast>
<visual baseUri="https://storage.googleapis.com/rppico.appspot.com/">
<binding template="ToastGeneric">
<text>Today will be sunny with a high of 63 and a low of 42.</text>
<group>
<subgroup hint-weight="1">
<text hint-align="center">Mon</text>
<image src="Mostly Cloudy.png" hint-removeMargin="true"/>
<text hint-align="center">63°</text>
<text hint-style="captionsubtle" hint-align="center">42°</text>
</subgroup>
<subgroup hint-weight="1">
<text hint-align="center">Tue</text>
<image src="Cloudy.png" hint-removeMargin="true"/>
<text hint-align="center">57°</text>
<text hint-style="captionsubtle" hint-align="center">38°</text>
</subgroup>
<subgroup hint-weight="1">
<text hint-align="center">Wed</text>
<image src="Sunny.png" hint-removeMargin="true"/>
<text hint-align="center">59°</text>
<text hint-style="captionsubtle" hint-align="center">43°</text>
</subgroup>
<subgroup hint-weight="1">
<text hint-align="center">Thu</text>
<image src="Sunny.png" hint-removeMargin="true"/>
<text hint-align="center">62°</text>
<text hint-style="captionsubtle" hint-align="center">42°</text>
</subgroup>
<subgroup hint-weight="1">
<text hint-align="center">Fri</text>
<image src="Sunny.png" hint-removeMargin="true"/>
<text hint-align="center">71°</text>
<text hint-style="captionsubtle" hint-align="center">66°</text>
</subgroup>
</group>
</binding>
</visual>
</toast>
"@
$XmlDocument = [Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime]::New()
$XmlDocument.loadXml($xml)
$AppId = 'Microsoft.WindowsTerminal_8wekyb3d8bbwe!App'
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime]::CreateToastNotifier($AppId).Show($XmlDocument)
baseUri
で既定のパスを設定できます。
音楽を再生したり、フォルダを開いたり
$xml = @"
<toast>
<visual>
<binding template="ToastGeneric">
<text>Music Player</text>
<text>Download Finished</text>
</binding>
</visual>
<actions>
<action content="Play" activationType="protocol" arguments="C:\Windows\Media\Alarm01.wav" />
<action content="Open Folder" activationType="protocol" arguments="file:///C:/Windows/Media" />
</actions>
</toast>
"@
$XmlDocument = [Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime]::New()
$XmlDocument.loadXml($xml)
$AppId = '{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\WindowsPowerShell\v1.0\powershell.exe'
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime]::CreateToastNotifier($AppId).Show($XmlDocument)
コンテンツなし
$XmlDocument = [Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime]::New()
$XmlDocument.loadXml('<toast></toast>')
$AppId = '{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\WindowsPowerShell\v1.0\powershell.exe'
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime]::CreateToastNotifier($AppId).Show($XmlDocument)
コールバック
PowerShell 7.1 以降を使う場合
Invoke-WebRequest https://github.com/Windos/BurntToast/raw/main/BurntToast/lib/Microsoft.Windows.SDK.NET/WinRT.Runtime.dll -OutFile WinRT.Runtime.dll
Add-Type -Path WinRT.Runtime.dll
Invoke-WebRequest https://github.com/Windos/BurntToast/raw/main/BurntToast/lib/Microsoft.Windows.SDK.NET/Microsoft.Windows.SDK.NET.dll -OutFile Microsoft.Windows.SDK.NET.dll
Add-Type -Path Microsoft.Windows.SDK.NET.dll
$xml = @"
<toast>
<visual>
<binding template="ToastGeneric">
<text>Hello World</text>
<text>This is a simple toast message</text>
</binding>
</visual>
<actions>
<input id="textBox" type="text"/>
<action content="Send" activationType="system" arguments="dismiss" />
</actions>
</toast>
"@
$XmlDocument = [Windows.Data.Xml.Dom.XmlDocument]::New()
$XmlDocument.loadXml($xml)
$toast = [Windows.UI.Notifications.ToastNotification]::New($XmlDocument)
Register-ObjectEvent -InputObject $toast -EventName Activated -Action {
Write-Host $Event.SourceArgs.Arguments
Write-Host $Event.SourceArgs.UserInput.Value
}
[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier().Show($toast)
マイクロソフトストアで最新のPowerShellをインストールできます
PowerShell 7.1 以前を使う場合
Invoke-WebRequest https://github.com/GitHub30/PoshWinRT/releases/download/1.2/PoshWinRT.dll -OutFile PoshWinRT.dll
$xml = @"
<toast>
<visual>
<binding template="ToastGeneric">
<text>Hello World</text>
<text>This is a simple toast message</text>
</binding>
</visual>
<actions>
<input id="textBox" type="text"/>
<action content="Send" activationType="system" arguments="dismiss" />
</actions>
</toast>
"@
$XmlDocument = [Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime]::New()
$XmlDocument.loadXml($xml)
$toast = [Windows.UI.Notifications.ToastNotification, Windows.UI.Notifications, ContentType = WindowsRuntime]::New($XmlDocument)
function WrapToastEvent {
param($target, $eventName)
Add-Type -Path PoshWinRT.dll
$wrapper = new-object "PoshWinRT.EventWrapper[Windows.UI.Notifications.ToastNotification,System.Object]"
$wrapper.Register($target, $eventName)
}
Register-ObjectEvent -InputObject (WrapToastEvent $toast 'Activated') -EventName FireEvent -Action {
Write-Host arguments:, $args[1].Result.arguments
Write-Host textBox:, $args[1].Result.userinput['textBox']
}
$AppId = '{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\WindowsPowerShell\v1.0\powershell.exe'
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime]::CreateToastNotifier($AppId).Show($toast)
また、httpの画像を使用するにはSetting
がc:internet
を含むAppIDを使用する必要があります。Microsoft.WindowsTerminal_8wekyb3d8bbwe!App
など。ローカルの画像を使う場合は問題ありません。
References