osascript -e 'display notification "Lorem ipsum dolor sit amet" with title "Title"'
new ToastContentBuilder()
.AddToastActivationInfo("app-defined-string", ToastActivationType.Foreground)
.AddText("Some text")
.AddButton("Archive", ToastActivationType.Background, "archive")
.AddAudio(new Uri("ms-appx:///Sound.mp3"));
Interesting, thanks. And that gave me a clue on what to search for when it comes to Windows, which led to these:
And for posterity, here's roughly how to produce a notification on macOS:
- https://gist. github. com/Windos/9aa6a684ac583e0d38a8fa68196bc2dc (remove the spaces I had to force in there so the editor wouldn't embed the gist here)
- https://stackoverflow.com/questions...indows-fall-creators-update/46817674#46817674
- https://github.com/Windos/BurntToast
- macOS documentation: https://developer.apple.com/library...ationScriptingGuide/DisplayNotifications.html
- Windows documentation: https://docs.microsoft.com/en-us/wi...aptive-interactive-toasts?tabs=builder-syntax
B4X:osascript -e 'display notification "Lorem ipsum dolor sit amet" with title "Title"'
And the same on Windows:
B4X:new ToastContentBuilder() .AddToastActivationInfo("app-defined-string", ToastActivationType.Foreground) .AddText("Some text") .AddButton("Archive", ToastActivationType.Background, "archive") .AddAudio(new Uri("ms-appx:///Sound.mp3"));
@echo off
if "%~1"=="" call :printhelp & exit /b 1
setlocal
if "%~2"=="" (set Icon=Information) else (set Icon=%2)
powershell -Command "[void] [System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms'); $objNotifyIcon=New-Object System.Windows.Forms.NotifyIcon; $objNotifyIcon.BalloonTipText='%~1'; $objNotifyIcon.Icon=[system.drawing.systemicons]::%Icon%; $objNotifyIcon.BalloonTipTitle='%~3'; $objNotifyIcon.BalloonTipIcon='None'; $objNotifyIcon.Visible=$True; $objNotifyIcon.ShowBalloonTip(5000);"
endlocal
goto :eof
:printhelp
echo USAGE: %~n0 Text [Icon [Title]]
echo Icon can be: Application, Asterisk, Error, Exclamation, Hand, Information, Question, Shield, Warning or WinLogo
exit /b
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.RootPane.LoadLayout("Layout1")
MainForm.Show
xui.SetDataFolder("MyApp")
File.Copy(File.DirAssets, "notification.bat", xui.DefaultFolder, "notification.bat")
End Sub
Sub ShowNotification (Body As String, Title As String)
Dim shl As Shell
shl.Initialize("shl", "cmd.exe", Array("/c", File.Combine(xui.DefaultFolder, "notification.bat"), Body, "Information", Title))
shl.Run(10000)
Wait For shl_ProcessCompleted (Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
Log(Success)
End Sub
It is probably impossible, but it can still be useful.only problem is getting that is running from powershell...
https://eddiejackson.net/wp/?p=18877B4X:Sub AppStart (Form1 As Form, Args() As String) MainForm = Form1 MainForm.RootPane.LoadLayout("Layout1") MainForm.Show xui.SetDataFolder("MyApp") File.Copy(File.DirAssets, "notification.bat", xui.DefaultFolder, "notification.bat") End Sub Sub ShowNotification (Body As String, Title As String) Dim shl As Shell shl.Initialize("shl", "cmd.exe", Array("/c", File.Combine(xui.DefaultFolder, "notification.bat"), Body, "Information", Title)) shl.Run(10000) Wait For shl_ProcessCompleted (Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String) Log(Success) End Sub
It is probably impossible, but it can still be useful.
Sub Process_Globals
Private fx As JFX
Private MainForm As Form
Private xui As XUI
Private Button1 As B4XView
Dim img As Image
End Sub
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.RootPane.LoadLayout("Layout1")
MainForm.Show
img.Initialize("c:/temp","icontest.png")
End Sub
Sub Button1_Click
asJO(Me).RunMethod("displayTray",Array(img,"test1","test text"))
End Sub
Sub asJO (o As JavaObject) As JavaObject
Return o
End Sub
#if java
import java.awt.*;
import java.awt.event.*;
import java.awt.TrayIcon.MessageType;
import java.net.MalformedURLException;
import javafx.embed.swing.SwingFXUtils;
public static void displayTray(javafx.scene.image.Image img,String title,String msg) throws AWTException, MalformedURLException {
SystemTray tray = SystemTray.getSystemTray();
TrayIcon trayIcon = new TrayIcon(SwingFXUtils.fromFXImage(img, null));
tray.add(trayIcon);
trayIcon.displayMessage(title,msg, MessageType.INFO);
}
#End If
Very cool! You seem to have a nice solution there, I have a some follow-up questions:This will generate a windows notification