Giter Club home page Giter Club logo

Comments (11)

Windos avatar Windos commented on August 16, 2024 4

There is! I (finally) realised this while working on v0.6.0 but didn't have a chance to document it before release.

Unfortunately at the moment it's not possible to do this using only the New-BurntToastNotification function, so you need to dive into the more advanced functions:

$Text1 = New-BTText -Content 'Google!'
$Text2 = New-BTText -Content 'Clicking this will open Google.'

$Binding1 = New-BTBinding -Children $Text1, $Text2

$Visual1 = New-BTVisual -BindingGeneric $Binding1

$Content1 = New-BTContent -Visual $Visual1 -Launch 'https://google.com' -ActivationType Protocol

Submit-BTNotification -Content $Content1

The key to this is on the New-NTContent function: defining the -Launch as the url/uri/path you want to open, and setting the -ActivationType to Protocol.

Note that if you have buttons or progress bars or anything else on there, the clickable area is only the pictures/main text (clicking to progress bar is a deadzone, from memory)

I'll hopefully figure out a way to make this easier in the next release.

from burnttoast.

Windos avatar Windos commented on August 16, 2024 2

I know this is an old issue, but it deserves a wrap up with links to relevant info.

First, Custom URIs/Protocol Handlers: @adamdriscoll does an awesome job of showing this in this Module Monday video on BurntToast. I've also demo'ed it for the Research Triangle PowerShell User Group, the sample code for that is on their repo.

Second, ACTIONABLE TOASTS!

It's now possible to run any code via a toast notification action. This does require PowerShell 7.1 or above and BurntToast 0.8.0.

This blog post shows it in action, though with v0.8.0 it's a lot easier to take advantage of this via some new parameters on New-BurntToastNotification and Submit-BTNotification. Documentation for this is coming soon, for now check out the end of this live stream.

from burnttoast.

1mm0rt41PC avatar 1mm0rt41PC commented on August 16, 2024 1

An other way could be to create a new handler for a internal protocol.
$Content1 = New-BTContent -Visual $Visual1 -Launch 'BurntToast://my-data' -ActivationType Protocol
But this tricks dosen't work with complex toast:

<toast duration="5">
    <visual>
        <binding template="ToastGeneric">
            <text>This is a test</text>
            <text />
            <text>This more testing</text>
            <text>RAWR</text>
            <image src="C:\Users\King\Documents\GitHub\BurntToast\Media\BurntToast.png" hint-removeMargin="false" />
        </binding>
    </visual>
    <audio src="ms-winsoundevent:Notification.SMS" />
    <actions>
        <input id="snoozeTime" type="selection" defaultInput="3">
            <selection id="1" content="1 Minutes" />
            <selection id="2" content="2 Minutes" />
            <selection id="3" content="3 Minutes" />
            <selection id="4" content="4 Minutes" />
            <selection id="5" content="5 Minutes" />
        </input>
        <action content="" arguments="snooze" activationType="system" />
        <action content="" arguments="dismiss" activationType="system" />
    </actions>
</toast>

from burnttoast.

dzfweb avatar dzfweb commented on August 16, 2024 1

@Windos
is there a way to call some function instead of launch browser?

In my case i want to focus a proccess by id.

Set-ForegroundWindow (Get-Process -id $procid).MainWindowHandle

from burnttoast.

1mm0rt41PC avatar 1mm0rt41PC commented on August 16, 2024

There is a bypass with a small dll.
See: https://deletethis.net/dave/2016-06/WinRT+Toast+from+PowerShell
May be it's possible to convert the C# dll in powershell script

from burnttoast.

Windos avatar Windos commented on August 16, 2024

Thanks for that link, very helpful. I'd considered bundling a compiled exe to handle this early on in the project and decided against it at the time.

I wonder if, like you say, it'd be possible to get this working in native PowerShell. We're working with PS5 here... so possibly PowerShell classes could be used.

As an aside, this issue prompted a blog post if anyone is interested.

from burnttoast.

Windos avatar Windos commented on August 16, 2024

I'll do some testing tonight, but thinking through it now: not directly because the string that's included as the action on a button isn't running inside PowerShell.

However, in theory anything you can do from the 'Run' dialogue should work where, so you might be able to start a PowerShell.exe instance with the function you want to run as an argument.

from burnttoast.

AmineI avatar AmineI commented on August 16, 2024

However, in theory anything you can do from the 'Run' dialogue should work where, so you might be able to start a PowerShell.exe instance with the function you want to run as an argument.

May I ask how would you launch an exe from a toast ? From my testing I could only launch files other than executables with that -launch:"" argument. Launching a .txt file opens the file in notepad, yet the exact path of notepad.exe didn't do the trick - Am I missing something there ?
Thanks in advance for your answer :)

from burnttoast.

SimonGLM avatar SimonGLM commented on August 16, 2024

Launching a .txt file opens the file in notepad, yet the exact path of notepad.exe didn't do the trick - Am I missing something there ?

If have tried a few things and the problem seems to correlate with what program you open the file with by default.
Say you insert the path of your test.ps1 into the launch parameter and execute the toast, the launch action will not be executed.
But if you choose the standard program to always open .ps1-files (notepad++.exe, in my case) via the 'open with'-dialoge, running your toast.ps1 will open the test.ps1 in notepad++.

However choosing powershell.exe to be the default program doesn't do the trick either for some reason.

It seems to me like something in the code forbids executables to be executed...?

from burnttoast.

jholl016 avatar jholl016 commented on August 16, 2024

You have to use a custom URI. There are several people who have found that this approach works. Check out the comments on this thread:

#22

from burnttoast.

SimonGLM avatar SimonGLM commented on August 16, 2024

Thanks for the speedy answer.

But sadly I did not quite understand what to do to set up a custom URI. Looks like I'll have to invest some more time in the future

from burnttoast.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.