bhavya_w
bhavya_w

Reputation: 10077

OSX : check if screen is sleep or awake from command line

Is there any way by which i can check whether the screen is asleep or awake from the command line or by applescript ?

Related to this - Check if display is sleeping in Applescript

A little background on why do i need to detect whether the screen state is sleep or awake :

I am creating an app using node-webkit and in the app we track the user's usage ( screenshot, process and website usage ) to calculate the total productive hours worked.

I need to detect the screen sleep / awake event so that i can start and stop the app acordingly.

In linux and windows I am able to detect this in Javascript ( Node webkit apps are built in Javascript ) as shown in the below mentioned links but that doesn't seem to be working in osx :

https://blog.alexmaccaw.com/javascript-wake-event

Can any desktop browsers detect when the computer resumes from sleep?

Upvotes: 3

Views: 2881

Answers (1)

oa-
oa-

Reputation: 371

"dsyp" is the value you are looking for:

set x to do shell script "ioreg -c AppleBacklightDisplay | grep brightness"

# lcd on:  dsyp\"={\"min\"=0,\"max\"=2,\"value\"=2}
# lcd off: dsyp\"={\"min\"=0,\"max\"=2,\"value\"=0}

Upvotes: 2

Related Questions