Ironman Software Forums
Continue the conversion on the Ironman Software forums. Chat with over 1000 users about PowerShell, PowerShell Universal, and PowerShell Pro Tools.
This blog post was requested by one of our users. Feel free to contact us if you have something you’d like to see.
To play sounds in Universal Dashboard, we’ll first need to host the sound files and then invoke some JavaScript to play the sound.
First, create a published folder that points to your media directory. I have a notification WAV file stored in this folder.
New-PSUPublishedFolder -RequestPath "/media" -Path "C:\ProgramData\UniversalAutomation\Repository\media"
Next, we can create a button on our dashboard to create a new Audio object and play it when the user clicks a button.
New-UDDashboard -Content {
New-UDButton -Text 'Notification' -OnClick {
Invoke-UDJavaScript -JavaScript 'var audio = new Audio("/media/notification.wav");
audio.loop = false;
audio.play(); '
}
}
It’s also possible to play the sound after some sort of processing or event takes place. For example, you could use New-UDDynamic
to load some data and then play a sound once it completes.
New-UDDynamic -Content {
Start-Sleep 5
Show-UDToast "Notification!"
Invoke-UDJavaScript -JavaScript 'var audio = new Audio("/media/notification.wav");
audio.loop = false;
audio.play(); '
}
Find this useful? Please consider sharing this article. Have a question about PowerShell? Contact us and we'll write a post about it.
Continue the conversion on the Ironman Software forums. Chat with over 1000 users about PowerShell, PowerShell Universal, and PowerShell Pro Tools.
Receive once-a-month updates about Ironman Software. You'll learn about our product updates and blogs related to PowerShell.