LoginSignup
6
12

More than 5 years have passed since last update.

[powershell]トースト通知を行う。

Last updated at Posted at 2018-02-25

powershellでトースト通知を行う。

15分おきにトースト通知を行って
無為に時間が経過するのを防ぎたかった。

環境

PSVersion 5.1.16299.248
PSEdition Desktop

コード

[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] | Out-Null
[Windows.UI.Notifications.ToastNotification, Windows.UI.Notifications, ContentType = WindowsRuntime] | Out-Null
[Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime] | Out-Null

$app = '{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\WindowsPowerShell\v1.0\powershell.exe'

$template = @"
<toast duration="long">
    <visual>
        <binding template="ToastText02">
            <text id="1">test Title</text>
            <text id="2">test content</text>
        </binding>
    </visual>
  <actions>
  <input id="snoozeTime" type="selection" defaultInput="15">
    #5つまで
    <selection id="3" content="3 minutes" />
    <selection id="5" content="5 minutes" />
    <selection id="10" content="10 minutes" />
    <selection id="15" content="15 minutes" />
    <selection id="30" content="30 minutes" />
  </input>
  <action activationType="system" arguments="snooze" hint-inputId="snoozeTime" content=""/>
  <action activationType="system" arguments="dismiss" content=""/>
  </actions>
</toast>
"@

$xml = New-Object Windows.Data.Xml.Dom.XmlDocument
$xml.LoadXml($template)
$toast = New-Object Windows.UI.Notifications.ToastNotification $xml
[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($app).Show($toast )

参考URL

https://docs.microsoft.com/en-us/windows/uwp/design/shell/tiles-and-notifications/toast-xml-schema
https://steemit.com/powershell/@esoso/fun-with-toast-notifications-in-powershell
https://qiita.com/akiqsinco/items/0c0d5ae4abc756a594b3

6
12
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
12