How to create a simple "Please wait..." message?

Over the year, various posts in this forum have offered ways to display a simple “Please wait…” message while other AppleScript commands continue to run in the background. Some of these used the application “AppleScript Runner” or “Automator Runner” - but, as far as I can tell, neither of these exist in recent macOS versions.

Is there a simple way to create such a message? The best I can come up with (and I’m a complete beginner at this kind of thing) is this. First, create a script application called PleaseWait.app, with at least this code:

display dialog "Please wait ..." with title "Working" buttons {"OK"}
error number -128

Then create a testing script application, with the PleaseWait.app stored inside it, in a Contents:Helpers folder. The script for the application looks like this - and the lines that open Microsoft Word are only there as an EXAMPLE of commands that run in the background while the Please Wait message continues to be visible:

use scripting additions

set myPath to POSIX path of (path to me)
set pleaseWait to myPath & "Contents/Helpers/PleaseWait.app"
do shell script "open" & space & quoted form of pleaseWait

-- this is here only as an EXAMPLE of what might happen in the background! It's only an example!
tell application "Microsoft Word"
	activate
	quit
end tell
-- remember that the above four lines are only an EXAMPLE!

tell application "System Events"
	set pwID to (unix id of processes whose name is "PleaseWait")
	try
		do shell script "kill -9 " & pwID
	end try
end tell

There must be a better way than this, and I’ll be grateful for any suggestions about what it might be.

How about this? It uses my Custom Notification script idea. The advantage is you can adjust the notification as want. You can edit its window dimensions, position on the screen, font of the message inside the window, the time notification appears, the time it closes and so on.


use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "AppKit"
property wController : missing value -- outlet equivalent in AsObjC
property notificationTitle : "Working"
property aWidth : 300
property aHeight : 60
property notificationText : "
    Please wait ..."

my performSelectorOnMainThread:"displayNotification:" withObject:({aWidth, aHeight, notificationTitle, current application's NSString's stringWithString:notificationText}) waitUntilDone:true

-- this is here only as an EXAMPLE of what might happen in the background! It's only an example!
repeat with i from 5 to 1 by -1
	say i
	delay 1
end repeat
say "Start"
-- remember that the above 5 lines are only an EXAMPLE!

my closeNotification()


------------------------------------ HANDLERS ------------------------------------------------
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|:20)
	set aScreen to current application's NSScreen's mainScreen()
	set aFrame to {{0, 0}, {aWidth, aHeight}}
	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:0.9 --append
	aWin's setReleasedWhenClosed:true
	aWin's |center|()
	aWin's setContentView:aView
	aView's setString:notificationText
	set my wController to current application's NSWindowController's alloc()
	my (wController's initWithWindow:aWin)
	my (wController's showWindow:me)
end displayNotification:

on closeNotification()
	my wController's |close|()
end closeNotification

@KniazidisR - That’s perfect! Thank you! Is there a site where more of your sample code is posted?

Thank you again!