The idea of writing this script was prompted by a question from the user @Joy in the Screen filling overhead message topic (clickable). In which he never got the right answer.
-- script: Custom Display Notification using AsObjC
-- written: by me, right now
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "AppKit"
property wController : missing value -- outlet equivalent in AsObjC
property givingUpAfter : 3 -- seconds
set notificationTitle to "" -- no title
set {aWidth, aHeight} to {1200, 600}
set notificationText to "Happy New Year!!!"
set notificationText to current application's NSString's stringWithString:notificationText
set paramObj to {aWidth, aHeight, notificationTitle, notificationText}
my performSelectorOnMainThread:"displayNotification:" withObject:(paramObj) waitUntilDone:true
on displayNotification:paramObj
copy paramObj to {aWidth, aHeight, aTitle, notificationText}
set aColor to current application's NSColor's colorWithDeviceRed:0.0 green:0.0 blue:0.0 alpha:0.9
set aView to current application's NSTextView's alloc()'s initWithFrame:(current application's NSMakeRect(0, 0, aWidth, aHeight))
aView's setRichText:true
aView's useAllLigatures:true
aView's setTextColor:(current application's NSColor's cyanColor()) --
aView's setBackgroundColor:aColor
aView's setEditable:false
aView's setFont:(current application's NSFont's fontWithName:"Menlo" |size|:128)
set aWin to makeWinWithView(aView, aWidth, aHeight, aTitle, 0.9)
aView's setString:notificationText
set my wController to current application's NSWindowController's alloc()
my (wController's initWithWindow:aWin)
my (wController's showWindow:me)
delay givingUpAfter
my wController's |close|()
end displayNotification:
on makeWinWithView(aView, aWinWidth, aWinHeight, aTitle, alphaV)
set aScreen to current application's NSScreen's mainScreen()
set aFrame to {{0, 0}, {aWinWidth, aWinHeight}}
set aBacking to current application's NSTitledWindowMask
set aDefer to current application's NSBackingStoreBuffered
set aWin to current application's NSWindow's alloc()
(aWin's initWithContentRect:aFrame styleMask:aBacking backing:aDefer defer:false screen:aScreen)
aWin's setTitle:aTitle
aWin's setDelegate:me
aWin's setDisplaysWhenScreenProfileChanges:true
aWin's setHasShadow:true
aWin's setIgnoresMouseEvents:false
aWin's setLevel:(current application's NSNormalWindowLevel)
aWin's setOpaque:false
aWin's setAlphaValue:alphaV --append
aWin's setReleasedWhenClosed:true
aWin's |center|()
aWin's setContentView:aView
return aWin
end makeWinWithView