Now for the suppression button. This is simply a matter of making sure it shows -- by calling setShowsSuppressionButton: -- and once the alert is dismissed, checking the state of the suppression button.
This code includes a repeat loop, to show how the suppression button works. Each time through the loop, a dialog appears and a voice speaks; once you click the suppress button, the dialog no longer appears.
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "AppKit" -- required for NSAlert
-- check we are running in foreground
if not (current application's NSThread's isMainThread()) as boolean then
display alert "This script must be run from the main thread." buttons {"Cancel"} as critical
error number -128
end if
-- for styleNum, 0 = warning, 1 = informational, 2 = critical
on displayAlert:mainText message:theExplanaton asStyle:styleNum buttons:buttonsList suppression:showSuppression
set buttonsList to reverse of buttonsList -- because they get added in reverse order cf AS
-- create an alert
set theAlert to current application's NSAlert's alloc()'s init()
-- set up alert
tell theAlert
its setAlertStyle:styleNum
its setMessageText:mainText
its setInformativeText:theExplanaton
repeat with anEntry in buttonsList
(its addButtonWithTitle:anEntry)
end repeat
its setShowsSuppressionButton:showSuppression
end tell
-- show alert
set returnCode to theAlert's runModal()
-- get values after alert is closed
set suppressedState to theAlert's suppressionButton()'s state() as boolean
set buttonNumber to returnCode mod 1000 + 1 -- where 1 = right-most button
set buttonName to item buttonNumber of buttonsList
return {buttonName, suppressedState}
end displayAlert:message:asStyle:buttons:suppression:
set showDialog to true -- start off showing dialog
repeat with i from 1 to 10
if showDialog then
set {buttonName, suppressedState} to (my displayAlert:"Decision time" message:("Do you want to munge item " & i & "?") asStyle:2 buttons:{"Cancel", "OK"} suppression:true)
-- if box was checked, we want showSuppression off next time
if suppressedState then set showDialog to false
end if
-- do what needs to be done, depending on buttonName, here
say ("Loop number " & i)
end repeat