REQ: Trigger for display wakeup

The existing triggers for before / after sleep are useful, however they only run when the Mac fully goes to sleep. Macs are able to power off displays without fully sleeping after a period of user inactivity (for example when running an app that prevents sleep or when playing audio). For me it would be very useful to trigger actions when the display powers back on.

I believe the relevant notification is kIOMessageDeviceHasPoweredOn

Ah, it looks like this should already be possible with the NSWorkspace notification trigger.

EDIT: NSWorkspaceScreensDidSleepNotification and NSWorkspaceScreensDidWakeNotification do not trigger for me unfortunately.

You can subscribe the triggers yourself using AppleScript according to this template:

If the script is started as a file at the start of BTT (important, because otherwise it runs in a script runner, which is terminated after execution), the triggers come reliably.

Edit: Here is the script for NSWorkspaceScreensDidWakeNotification based on the template:

script theScript
	use framework "Foundation"
	use scripting additions
	
	property ca : current application
	property workspaceClass : class "NSWorkspace"
	
	on addObserver()
		set ws to workspaceClass's sharedWorkspace()
		set nc to ws's notificationCenter()
		tell nc to addObserver:me selector:"screensDidWakeNotification:" |name|:"NSWorkspaceScreensDidWakeNotification" object:(missing value)
	end addObserver
	
	on screensDidWakeNotification:theNSNotification
		tell application "BetterTouchTool"
			--trigger your named trigger
			trigger_named "OnScreensDidWake"
		end tell
	end screensDidWakeNotification:
end script

theScript's addObserver()

Note: Of course it does not work if the option "Restart BTT after standby" is activated in BTT. In this case you can directly use the trigger "After BTT was started".

In the end, I was able to get the Received NSWorkspaceScreensDidWakeNotification trigger working using the BTT's built in support. The issue was that I had the trigger within a Conditional Activation Group. Even though the CAG should be active (it just checks for a BTT variable that's set to each Mac's serial number on launch) for some reason the NSWorkSpace trigger wasn't happening.

Once I moved the trigger out of the CAG into All Apps, it started working as expected.