Is it possible to assign a custom icon to a Dialog Toolkit dialog?

For example:

set {theButton, suppressedState} to display enhanced alert theTitle message theMessage with icon FilePathToTheImageFile as informational alert buttons {“Button 1”, “Button 2”} giving up after 0 acc view width 350 acc view height theTop acc view controls {} without suppression

Starting point :

Yvan KOENIG running Sierra 10.12.6 in French (VALLAURIS, France) mardi 1 aout 2017 23:15:09

If you’d like my copy of Shane’s Dialog Toolkit with a few modified functions, including the ability to use custom icons, you can download it here:

DISCLAIMER: I haven’t done anything I’m probably supposed to do about including a license, crediting Shane, etc. etc. in that file. I just dumped something that’s supposed to be for internal use on Dropbox, so please only use it for reference and understand that this is Shane’s code with just a few modifications I put in that may or may not be done correctly.

Edit: Note that I did not change any existing functions in the library, I only added new ones. So I did not add the custom icon to “display enhanced alert,” I added new functions “return enhanced alert” and “show returned alert,” and these allow the use of the custom icon.

It’s divided into the two parts so the script can modify variables in the alert before displaying it.

NSAlert by default will show the icon stored in YourApp/Contents/Resources/applet.icns. Save your custom images into that file. A tool like Icon Composer might help. For that to work add two lines of code to Shane’s Toolkit:

set appIcon to missing value -- located inside the on event handler before "tell alert"

its setIcon:appIcon – located inside the “tell alert” group.