Crouton #7 - Superhero Landing
Posted on May 12, 2018 • 3 minutes • 528 words
Ever find yourself needing to get an image up on your screen in a timely manner?
Yeah, me neither. But if you do find this to be the case then you can use a Toast Notification to do the job.
As with all of these “Crouton ” posts, you’ll need to have the BurntToast module installed in order to follow along.
Let’s say you have CCTV cameras outside your server rooms, and you want to get a snapshot when they pickup movement. Assuming your CCTV system can handle dumping a picture into a folder, you can watch for these images and display them as part of a toast.
I’m only going to focus on the construction of the Toast itself, not generating the picture or watching for new images (maybe we’ll do a post on FileSystemWatcher events soon.)
Plug in the Toaster
Unfortunately, we won’t be able to use
New-BurntToastNotification for this, so right off the bat you’ll have a few more lines of code than you might normally have had.
First, let’s sort out the text and image we’ll be using:
$Text1 = New-BTText -Content 'Intruder Alert!' $Text2 = New-BTText -Content 'CCTV has picked up motion outside Server Room 1' $Image1 = New-BTImage -Source 'C:\cctv\2018-05-13-12-53.jpg' -HeroImage
Notice the switch on our image,
-HeroImage. This designates that the image is to be featured very prominently at the top of the Toast.
Next “bind” together all of our text elements and the hero image, and pass that binding into a visual element:
$Binding = New-BTBinding -Children $Text1, $Text2 -HeroImage $Image1 $Visual = New-BTVisual -BindingGeneric $Binding
Finally, choose a sound to accompany the toast. I’m going with one of the built in alarm sounds, but you could choose a claxon if you really wanted to. Create a content element then submit it to be displayed:
$Audio1 = New-BTAudio -Source ' ms-winsoundevent:Notification.Looping.Alarm' -Loop $Content = New-BTContent -Audio $Audio1 -Visual $Visual -Duration Long Submit-BTNotification -Content $Content
-Loop on my sound so that it keeps playing while the Toast is on screen, and set the duration to Long so that it’s on the screen for a while (I really want to get this CCTV notification.)
When you run this, you’ll get your rather spiffy looking Toast:
This post has been a long time coming. My last one went out the day I went back to work after a couple of weeks off… and it took a while to catch back up. Doesn’t help that I’m also working on a couple of side projects at the moment which means this blog took a back seat for a little while.
The only project I’ll mention now (and expect to hear more about it in the future), is Adam Bertram’s upcoming e-learning service TechSnips . I’ve been busy recording “snips” ready for the official launch on the 5th of June. If you’re interested in getting in on the early soft launch, and get a 25% discount, make sure to check out www.techsnips.io and register your interest at the bottom of the page!
Also, remember that if you’re looking for PowerShell help , you can find it on Twitter using #PSHelp !comments powered by Disqus