How to detect display sleep on Apple Silicon

I have a script library function below which detects display sleep on Intel processor but I need to do the same for Apple Silicon. Can anyone suggest a solution?

on getSleepState()
	set theArch to do shell script "uname -m"
	if theArch is "x86_64" then -- Intel
		set display_sleep_state to do shell script "ioreg -n IODisplayWrangler |grep -i IOPowerManagement"
		if display_sleep_state contains "\"CurrentPowerState\"=4" then
			return "display awake"
		else
			return "display asleep"
		end if
	else
		return ""
	end if
end getSleepState

What does

In the Terminal tell you?

Thanks for the suggestion but it shows nothing on my machine (Mac mini M2 Pro)

You can get display sleep/awake notification.

http://piyocast.com/as/archives/5281

This means if you run residential AppleScript to receive notification messages, you can do it.

But we have to know the way to know the display awake/sleep state via ioreg or the other tools. Apple Silicon Macs are computers that are nothing like Intel Macs. So, ioreg access should be different.

Thanks Piyomaru. My understanding of the two scripts is that they function only on moment the computer is put to sleep or woken - or am I wrong? Certainly running them on my machine from Script Debugger does not return the current sleep sate. I need to be able to query the current sleep state of the display at any particular time from an AS app that continuously runs in the background on the machine.

You’re right. These 2 scripts inform you when your display sleep / awake.
It can not detect current sleep/awake status.

But these script inform after Script Debugger’s execution finished. Cocoa objects stay on memory after script execution though Script Debugger seems stop. It is a funny funny behavior:-).

Thanks for the suggested code. I tried the AS and it returned DarkWake - which I assume means something like waking from deep sleep? Unfortunately even on my machine execution is a bit to slow. Its part of a video notification system so I need it to be as instant as possible.

UPDATE: With a bit of fiddling with Fredrik71’s solution…

on getSleepState()
	set theArch to do shell script "uname -m"
	if theArch does not contain "arm" then -- Intel
		set display_sleep_state to do shell script "ioreg -n IODisplayWrangler |grep -i IOPowerManagement"
		if display_sleep_state contains "\"CurrentPowerState\"=4" then
			return "display awake"
		else
			return "display asleep"
		end if
	else if theArch contains "arm" then -- Apple Silcon
		-- slow
		set theResult to (do shell script "pmset -g log | grep -e \" Sleep  \" -e \" Wake  \" | tail -n1") as text
		set theItems to returnList(theResult, tab)
		set theTime to text from word 1 to word ((count of words in item 1 of theItems) - 1) of item 1 of theItems
		set theState to last word of item 1 of theItems
		set theMsg to last item of theItems
		if theState is "Wake" then
			return "display awake"
		else
			return "display asleep"
		end if
	else -- Don't know
		return ""
	end if
end getSleepState


on returnList(theText, theOriginalDelim)
	tell (a reference to my text item delimiters)
		set {oldDelim, contents} to {contents, theOriginalDelim}
		set {theText, contents} to {theText's text items, ","}
		set {theText, contents} to {theText as list, oldDelim}
	end tell
	return theText
end returnList