Sorry I didn't respond to this earlier - for some reason I didn't get an email notification.
If you specifically want newlines, then I would recommend using a "set variable to text" to set the multiline text, then use that as a parameter. Several of the demos do that.
If the text doesn't fit on the screen, it wraps automatically.
This is a very nice addition to Keyboard Maestro. Thank you!
Is there any way to create a setting that prevents the notification window from stealing the focus when it is displayed? I have a macro that runs continuously and it occasionally calls this macro. If I typing in another application this macro can steal the focus and my typing is blocked and I get error beeps until the Display Text window times out.
I tried to solve this when working with @martin's macro. I am not a html, CSS, javascript expert and could not find a solution.
You're the expert on that action, so I believe you.
However when I want a window to display text without grabbing the focus, I use Display Progress Bar which allows you to display a line of text on a window without grabbing focus. And it's easy to close programatically, as well.
Barring an "official" solution, I've had a quick play and immediately preceding your "Custom HTML Prompt" call with this async AS action may solve the problem:
tell application "Keyboard Maestro Engine"
try
set startWinID to id of window 1
on error
set startWinID to 0
end try
set winID to startWinID
repeat until winID ≠ startWinID
delay 0.1
try
set winID to id of window 1
on error
set winID to 0
end try
end repeat
do script "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">
<plist version=\"1.0\">
<array>
<dict>
<key>Action</key>
<string>SelectWindow</string>
<key>MacroActionType</key>
<string>ManipulateWindow</string>
<key>TargetApplication</key>
<dict/>
<key>Targeting</key>
<string>FrontWindow</string>
<key>TargetingType</key>
<string>Front</string>
</dict>
</array>
</plist>"
end tell
Demo -- change hot key to something unique, run with a window in another app active:
Note that palettes are also engine windows, which is why this needs a unique trigger to avoid the Conflict Palette. There might be a way to work round that if it's an issue.
Logs the id of the frontmost Engine window (0 if none present), and when that changes (new HTML prompt [or, grrr, palette, etc]) sends the KM "activate front window of front application" action to bring your "working" window back into focus.
I added this script call and it does help considerably. I reduced the delay to 0.02 seconds (not sure if this actually helps). I can now be typing in a separate application with multiple rapid asynchronous calls to "Display Large Text Notification" occurring. I still get occasional beeps when this occurs but focus always returns very quickly to the app where I am typing.
The smaller the delay, the more frequent the check for the arrival of the HTML Prompt. The more frequent the check, the quicker focus will be returned to your active window. But the more frequent the check, the more OS resources devoted to doing the check.
So it's a balancing act -- make the delay as short as you can, but not to the point where it impacts the other things you are doing.
I just uploaded v1.1a, to fix a typo in the HTML file.
If you're wondering how this got past my testing, it's because I tested with the HTML file from my "development" folder, and forgot to copy it into the KM Action. D'OH!
A big thank you to @2326685899kk for spotting the error, and even going through the effort of tracking it down in the HTML file!