Author Topic: How to generate a Windows 10 desktop notification  (Read 483 times)

td

  • Tech Support
  • *****
  • Posts: 3747
    • WinBatch
Re: How to generate a Windows 10 desktop notification
« Reply #35 on: May 31, 2021, 05:39:01 pm »
I was joking about the PS comment as I figured it would get you to comment.

Just wanted to give due credit where credit was due.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

stanl

  • Pundit
  • *****
  • Posts: 1447
Re: How to generate a Windows 10 desktop notification
« Reply #36 on: June 01, 2021, 01:07:47 pm »
Just wanted to give due credit where credit was due.


Tony:  understood


Jim: Don't take what I wrote with any importance. I have no need for notifications but the concept of compiling C# should be of interest to all, so hope you get more feedback on that. I'm surprised no interest in the Power Query scripts I posted but such is the nature of things.

JTaylor

  • Pundit
  • *****
  • Posts: 1667
    • Data & Stuff Inc.
Re: How to generate a Windows 10 desktop notification
« Reply #37 on: June 01, 2021, 01:35:55 pm »
No problem Stan.  I am not sure I have any use for Toasts either but was just something interesting to work on.   I am very glad this went the way it did because the in-memory compiling code I have used for years stopped working for some reason I couldn't figure out.  This thread provided an example that worked so happy on that front as well.


Jim   

ChuckC

  • Sr. Member
  • ****
  • Posts: 321
Re: How to generate a Windows 10 desktop notification
« Reply #38 on: June 02, 2021, 04:23:00 am »
If you have a WinBatch script running in the SysTray or otherwise running in the background [minimized], Toast notifications would serve nicely as a way to deliver a notification to the user in a way that doesn't require the script to be blocked by using the Display() function or having to use the Dialog() or Box*() functions.

That's one usage case that stands out to me.  I'm certain that a little more experimental coding and testing will get embedded images, playing of sound and configurable action buttons would make usage of Toast notifications even more desirable.

As for the in-memory compilation, I use it extensively in my PowerShell script development.  One thing I had to account for in the C# code I originally posted is that the built-in C# compiler that is present with .NET Framework v4.x is for a much older language version than what is currently available with Visual Studio.  The C# compiler, code name "Roslyn", is available for use outside of Visual Studio and exists as a redistributable set of binaries that I use with PowerShell.  I can see about posting a WinBatch script that does in-memory compilation of C# code using Roslyn so that all kinds of newer C# language features are accessible.


JTaylor

  • Pundit
  • *****
  • Posts: 1667
    • Data & Stuff Inc.
Re: How to generate a Windows 10 desktop notification
« Reply #39 on: June 02, 2021, 12:37:17 pm »
Sounds good to me, if you get the time.

Thanks.

Jim

seckner

  • Jr. Member
  • **
  • Posts: 69
Re: How to generate a Windows 10 desktop notification
« Reply #40 on: June 04, 2021, 03:16:18 pm »
Not sure if this will help but I found this script buried in the basement of the WinBatch office building. It will post a notification on one or many clients. Overnight jobs will post a message and not fade it out, daily jobs would post a notify an fade out in x seconds or minutes. The original web site has been changed and there are many GitHub sites with it. I don't know if the files are safe anymore. I have all the original files if needed. It's not fancy but it works.

https://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/nftechsupt.web+WinBatch/Samples~from~Users+Growl~Notify~~UDF.txtf

If there is any interest I'll gather the Files.

td

  • Tech Support
  • *****
  • Posts: 3747
    • WinBatch
Re: How to generate a Windows 10 desktop notification
« Reply #41 on: June 04, 2021, 11:14:55 pm »
 Looks like you have an extra character at the end of your URL. It should be

https://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/nftechsupt.web+WinBatch/Samples~from~Users+Growl~Notify~~UDF.txt

with the "f" removed from the end.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

stanl

  • Pundit
  • *****
  • Posts: 1447
Re: How to generate a Windows 10 desktop notification
« Reply #42 on: June 05, 2021, 04:44:56 am »
If there is any interest I'll gather the Files.


There is a March 2021 release on FileHippo, which is clean. The script you referenced does work, but it probably needs an IsGrowlRunning() in order for notifications to show up. Good find especially for the Op's original question.

td

  • Tech Support
  • *****
  • Posts: 3747
    • WinBatch
Re: How to generate a Windows 10 desktop notification
« Reply #43 on: June 05, 2021, 08:03:05 am »
The (hopefully) useful stuff users find in the Tech Database never ceases to amaze.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

kdmoyers

  • Sr. Member
  • ****
  • Posts: 411
Re: How to generate a Windows 10 desktop notification
« Reply #44 on: June 08, 2021, 12:54:32 pm »
There is a March 2021 release on FileHippo, which is clean.

Stan,
Just want to be sure I'm getting the same version you got. 
(The file I see on Hippo is dated march of 2012, not 2021.)

is it version 2.0.9.1 ?  with the file Gowl_v2.0.msi shows a CRC-32 of 5143A96A?

Thanks!!
-Kirby
The mind is everything; What you think, you become.

ChuckC

  • Sr. Member
  • ****
  • Posts: 321
Re: How to generate a Windows 10 desktop notification
« Reply #45 on: June 08, 2021, 01:33:44 pm »
I got things working with PowerShell generating toast notifications which contain images.

PS code snippets:


$inlineImageFileSpec = Join-Path $PSScriptRoot "ButteredToast.jpg"

$appLogoImageFileSpec = Join-Path $PSScriptRoot "Toaster.jpg"

$heroImageFileSpec = Join-Path $PSScriptRoot "A toast to you.jpg"


$toast = [Microsoft.Toolkit.Uwp.Notifications.ToastContentBuilder]::new()


#  An inline image is optional

$toast.AddInlineImage([System.Uri]::new("file://$($inlineImageFileSpec.Replace("\", "/"))"))


#  A profile [app logo override] image is optional

$toast.AddAppLogoOverride([System.Uri]::new("file://$($appLogoImageFileSpec.Replace("\", "/"))"))


#  This can be considered to the the "title" text on line #1.
#  A minimum of 1 line of text is required when preparing a
#  Toast Notification.

$toast.AddText("<Text Element #1>")

#  The remaining 2nd & 3rd text lines are optional.

$toast.AddText("<Text Element #2>")

$toast.AddText("<Text Element #3>")

#  The attribution text is optional.

$toast.AddAttributionText("<Attribution Text>")


#  A hero image is optional.  Maximum image dimensions
#  are 364x180 pixels at 100% scaling.

$toast.AddHeroImage([System.Uri]::new("file://$($heroImageFileSpec.Replace("\", "/"))"))


#  Make the notification appear on the desktop.

$toast.Show()


The pertinent lines of code can readily be adapted to the cleaned up dynamically compiled C# code that JT contributed in an earlier post in this thread.

For testing with PowerShell, the code above was written assuming that the files were in the same location as the .ps1 script file itself.  Please note that the paths must be converted to "file://" URI format where all back slashes in the path are converted to forward slashes.  The image files I used are quite small, but are apparently too large to attach here.

JTaylor

  • Pundit
  • *****
  • Posts: 1667
    • Data & Stuff Inc.
Re: How to generate a Windows 10 desktop notification
« Reply #46 on: June 08, 2021, 07:12:03 pm »
Just out of curiosity...did you do something different than what I did with images?   You mentioned adapting it to what I posted so was curious as what I posted handled images along with other features.   Want to make sure I don't miss something interesting.

Jim

I got things working with PowerShell generating toast notifications which contain images.



The pertinent lines of code can readily be adapted to the cleaned up dynamically compiled C# code that JT contributed in an earlier post in this thread.

For testing with PowerShell, the code above was written assuming that the files were in the same location as the .ps1 script file itself.  Please note that the paths must be converted to "file://" URI format where all back slashes in the path are converted to forward slashes.  The image files I used are quite small, but are apparently too large to attach here.

stanl

  • Pundit
  • *****
  • Posts: 1447
Re: How to generate a Windows 10 desktop notification
« Reply #47 on: June 09, 2021, 02:49:33 am »

Stan,
Just want to be sure I'm getting the same version you got. 
(The file I see on Hippo is dated march of 2012, not 2021.)

is it version 2.0.9.1 ?  with the file Gowl_v2.0.msi shows a CRC-32 of 5143A96A?

Thanks!!
-Kirby


I think 2012 was when it was first added to Hippo, but you probably got the latest release [still 2.09].


ChuckC

  • Sr. Member
  • ****
  • Posts: 321
Re: How to generate a Windows 10 desktop notification
« Reply #48 on: June 09, 2021, 08:15:37 am »
Just out of curiosity...did you do something different than what I did with images?


Ignore my post.  I was busily pasting in portions of code from different scripts and writing up the rest of the posting and then realized that I needed to go back and modify some of the sample PowerShell code to make use of an alternate method of utilizing Toast Notifications that may well eliminate the need for dynamically compiled C# code.  I meant to discard the incomplete posting... instead I clicked thru the post button in my haste to go pursue a "shiny thing".

The alternate method of using Toast Notifications involves directly composing the underlying XML that is sent to the listener that receives & displays the notifications.  It also allows proper population of XML elements that make it more readily possible to invoke a script as an action.  I was already doing some of that in PowerShell, but realized the respond-to-notification-being-clicked functionality won't port to WinBatch in a way that allows the script instance that generated the toast notification to get called back.  However, the fallback mechanism will allow a script to be invoked, with parameters, even though it won't be the exact same instance of the script that generated the toast notification.

JTaylor

  • Pundit
  • *****
  • Posts: 1667
    • Data & Stuff Inc.
Re: How to generate a Windows 10 desktop notification
« Reply #49 on: June 09, 2021, 08:39:33 am »
Okay.

The button-click/script call was something I was going to investigate more along with the XML.  Didn't see an immediate way to do that via WinBatch but intended to follow up.

Jim