Powershell : burnt toast notification

Iam creating a pomodoro timer using powershell. testing it with 1 minute interval to display the toast notification.

The below script however does not display the notification after 1 minute.
any advice from the experts will be helpful

function start-pomodoro {

$minutes = 1

$seconds = 60 * $minutes
$sb = {
Start-Sleep -Seconds $args[0]
New-BurntToastNotification -Text ‘Its Time to take a break, relax!!!MOve your body and come back’

}

start-job -Name start-pomodoro -ScriptBlock $sb -ArgumentList $seconds
}

Please … When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.

Thanks in advance

How to format code in PowerShell.org 1 <---- Click :point_up_2:t4: :wink:

( !! Sometimes the preformatted text button hides behind the settings gear symbol. :wink: )

I’m not familiar with what a pomodoro timer is - I assume it is something you need to install before you’re able to use it. And since the function New-BurntToastNotification is not part of the default installation of PowerShell as well I’d like to ask you if you have installed all needed dependencies and if there are any error messages when you run this code manually - I mean outside of a job.

toast notifications are installed… please see the image.I needed to basically display a text message after 1 minute

I am fairly certain the reason it doesn’t work is because Start-Job doesn’t interact with your user session. You could just have the Powershell script run from a Scheduled task under your user context

1 Like

i had to search, but it looks like New-BurntToastNotification is part of this module:

looking at one of the lines of code:

[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($AppId).Show($Toast)

it looks like the Typename they leverage has “UI” in it which supports @neemobeer idea. If you’re trying to leverage BurntToast notifications you likely won’t be able to do it from inside of a Job. Scheduled tasks can run as a given user if that’s what you really need like he also suggested.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.