SnoreToast Documentation

repository·master·Indexed 18 days ago

https://github.com/kde/snoretoast

A command-line utility for Windows 8 and later that enables developers to trigger native Windows Toast notifications. It supports custom titles, messages, images (.png), buttons, text inputs, and sounds. The tool includes functionality for branding notifications via AppID registration using the -install command, managing notification lifecycles with unique IDs, and integrating with NSIS installers or Appx package manifests for callback activations.

Tokens
5.4K
Snippets
16
Records
21
Agent score
52%

What's inside SnoreToast

  1. Overview of SnoreToast

    master

    SnoreToast is a command-line application used to create Windows Toast notifications on Windows 8 or later. It allows developers to trigger desktop notifications with custom titles, messages, images, buttons, and text inputs.

    By default, if no --appID is provided, SnoreToast creates a shortcut to snoretoast.exe in the Start Menu, and notifications will be branded as 'SnoreToast'. To brand notifications as your own application, you must register an application entry in the Start Menu using the -install command and then reference that specific AppID in subsequent calls.

  2. Image requirements for Toast notifications

    master

    When using the -p or --image option, images must adhere to the following constraints imposed by the Windows Toast notification system:

    • Format: .png only.
    • Dimensions: Maximum 1024x1024 pixels.
    • File Size: Must be <= 200kb.
  3. Manage notification lifecycle with IDs

    master

    To interact with a notification after it has been displayed (such as closing it), you must assign it a unique ID when it is created using the -id flag. You can then use the -close command with that ID to dismiss the notification programmatically.

    # Create a notification with a specific ID
    SnoreToast -t "Persistent" -m "Don't close me" -id "my_unique_id"
    
    # Close that specific notification later
    SnoreToast -close "my_unique_id"
  4. Install SnoreToast shortcut via CLI

    master

    You can use the -install command to create a Start Menu shortcut that points to a specific application and associates it with a specific AppID for notifications.

    # Syntax: SnoreToast -install <name> <application> <appID>
    SnoreToast -install "My App" "C:\Path\To\App.exe" "com.example.myapp"
  5. Use SnoreToast CLI to display notifications

    master

    SnoreToast is a command-line utility for displaying Windows toast notifications. You can specify titles, messages, buttons, images, and sounds using various flags.

    Basic Usage Pattern: SnoreToast [-t <title>] [-m <message>] [options]

    Common Options:

    • -t <title>: The first line of the toast.
    • -m <message>: The body text (supports wrapping).
    • -b <button1;button2>: Adds buttons to the bottom line (separate multiple buttons with ;).
    • -tb: Displays a textbox on the bottom line (only works if no buttons are provided).
    • -p <image URI>: Displays a local .png image.
    • -s <sound URI>: Sets a notification sound.
    • -silent: Shows the notification without playing a sound.
    • -d <short|long>: Sets duration (short is 7s, long is 25s).
    # Example: A toast with a title, message, and two buttons
    SnoreToast -t "Alert" -m "System update available" -b "Install;Later"
    
    # Example: A toast with an image and a textbox
    SnoreToast -t "Input Required" -m "Please enter your name" -p "C:\path\to\image.png" -tb
  6. Register SnoreToast with Appx (Package Manifest)

    master

    To enable toast notification activation (e.g., clicking a toast to trigger an action) within an Appx package, you must register the SnoreToast COM CLSID in your package manifest.

    Ensure you pass the -pid flag to SnoreToast when using this method. You must replace SNORETOAST_CALLBACK_GUID with your specific GUID.

    Manifest Snippet:

    <!--Register COM CLSID LocalServer32 registry key-->
    <com:Extension Category="windows.comServer">
        <com:ComServer>
        <com:ExeServer Executable="bin\snoretoast.exe" DisplayName="SnoreToast activator">
            <com:Class Id="SNORETOAST_CALLBACK_GUID" DisplayName="Toast activator"/>
        </com:ExeServer>
        </com:ComServer>
    </com:Extension>
    
    <!--Specify which CLSID to activate when toast clicked-->
    <desktop:Extension Category="windows.toastNotificationActivation">
        <desktop:ToastNotificationActivation ToastActivatorCLSID="SNORETOAST_CALLBACK_GUID" />
    </desktop:Extension>
    <!--Register COM CLSID LocalServer32 registry key-->
    <com:Extension Category="windows.comServer">
        <com:ComServer>
        <com:ExeServer Executable="bin\snoretoast.exe" DisplayName="SnoreToast activator">
            <com:Class Id="SNORETOAST_CALLBACK_GUID" DisplayName="Toast activator"/>
        </com:ExeServer>
        </com:ComServer>
    </com:Extension>
    
    <!--Specify which CLSID to activate when toast clicked-->
    <desktop:Extension Category="windows.toastNotificationActivation">
        <desktop:ToastNotificationActivation ToastActivatorCLSID="SNORETOAST_CALLBACK_GUID" />
    </desktop:Extension>
  7. Brand notifications with a custom AppID

    master

    To ensure notifications are branded with your application's identity rather than 'SnoreToast', follow these two steps:

    1. Register your application: Create a Start Menu entry that links your executable to a specific AppID using the -install flag.
    2. Use the AppID: When calling snoretoast.exe to show a notification, pass the same AppID using the --appID flag.

    Example Registration:

    snoretoast.exe --install "MyApp\MyApp.lnk" "C:\myApp.exe" "My.APP_ID"

    Example Notification:

    snoretoast.exe --appID "My.APP_ID" -t "Hello" -m "World"
    snoretoast.exe --install "MyApp\MyApp.lnk" "C:\myApp.exe" "My.APP_ID"
    snoretoast.exe --appID "My.APP_ID" -t "Hello" -m "World"
  8. Install SnoreToast shortcuts for AppID integration

    master

    To ensure notifications are correctly associated with a specific application (and appear in the Action Center under that app's identity), you can use the -install command. This creates a Windows shortcut that links an executable to an AppID.

    Syntax: snoretoast.exe -install "<path_to_shortcut>" "<path_to_executable>" "<AppID>"

    snoretoast.exe -install "C:\Users\Me\Desktop\MyApp.lnk" "C:\Program Files\MyApp\app.exe" "MyCompany.MyApp"
  9. Manage notification lifecycles with IDs

    master

    You can assign a unique identifier to a notification using the -id flag. This allows you to programmatically close a specific notification later using the -close flag.

    1. Create a notification with an ID: snoretoast.exe -t "Title" -m "Message" -id "my_unique_id"

    2. Close that specific notification: snoretoast.exe -close "my_unique_id"

    snoretoast.exe -t "Loading" -m "Please wait..." -id "loader_01"
    # ... later ...
    snoretoast.exe -close "loader_01"
  10. Create shortcuts with NSIS

    master

    If you are using an NSIS installer, you can use the provided macro to handle shortcut creation. The macro checks if the OS is at least Windows 8; if so, it uses snoretoast.exe -install to register the AppID and shortcut. Otherwise, it falls back to a standard CreateShortCut command.

    !include LogicLib.nsh
    !include WordFunc.nsh
    
    Function SnoreWinVer
        ReadRegStr $R0 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion" CurrentVersion
        ${VersionCompare} "6.2" $R0 $R0
        ${If} $R0 == 1
            Push "NotWin8"
        ${Else}
            Push "AtLeastWin8"
        ${EndIf}
    FunctionEnd
    
    !macro SnoreShortcut path exe appID
        Call SnoreWinVer
        Pop $0
        ${If} $0 == "AtLeastWin8"
            nsExec::ExecToLog '"${SnoreToastExe}" -install "${path}" "${exe}" "${appID}"'
        ${Else}
            CreateShortCut "${path}" "${exe}"
        ${EndIf}
    !macroend
    !include LogicLib.nsh
    !include WordFunc.nsh
    
    Function SnoreWinVer
        ReadRegStr $R0 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion" CurrentVersion
        ${VersionCompare} "6.2" $R0 $R0
        ${If} $R0 == 1
            Push "NotWin8"
        ${Else}
            Push "AtLeastWin8"
        ${EndIf}
    FunctionEnd
    
    !macro SnoreShortcut path exe appID
        Call SnoreWinVer
        Pop $0
        ${If} $0 == "AtLeastWin8"
            nsExec::ExecToLog '"${SnoreToastExe}" -install "${path}" "${exe}" "${appID}"'
        ${Else}
            CreateShortCut "${path}" "${exe}"
        ${EndIf}
    !macroend
  11. Requirements for Toast Images

    master

    When using the -p flag to display images in a toast, the images must adhere to the following constraints imposed by the Windows Toast notification system:

    • Format: Must be .png.
    • Dimensions: Maximum of 1024x1024 pixels.
    • File Size: Must be <= 200kb.