Skip to content

Instantly share code, notes, and snippets.

@ts1
Last active August 28, 2020 08:15
Show Gist options
  • Save ts1/dade56c2ef6d89f034f82f2e2d149003 to your computer and use it in GitHub Desktop.
Save ts1/dade56c2ef6d89f034f82f2e2d149003 to your computer and use it in GitHub Desktop.
Tiny command to detect whether Mac display is awake or asleep
#include <CoreGraphics/CoreGraphics.h>
int main()
{
return CGDisplayIsAsleep(CGMainDisplayID());
}
@ts1
Copy link
Author

ts1 commented Aug 28, 2020

Compile like this

cc -Wall -O2 awake.c -framework CoreGraphics -o awake

@ts1
Copy link
Author

ts1 commented Aug 28, 2020

Use in AppleScript

	try
		do shell script "/path/to/awake"
		-- display is awake
	on error
		-- display is asleep
	end try

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment