Activity on computers

Posted on
Sat Apr 04, 2015 9:26 am
Stoutjesdijk offline
User avatar
Posts: 135
Joined: Dec 21, 2014
Location: The Netherlands

Activity on computers

Hi all,

I have a motion sensor in my office. This turns on and off the lights. In this office, there are two computers: one for my wife, one for me. When we are working, we do not move around enough for the sensor to register. So, we'd be working in the dark all of a sudden.

How about indigo has a way to see if the screen saver is active on both computers? To start with an easy one, can this be done on the computer that runs the server (my own computer)? And more complicated, how about on my wife's computer?

All help and ideas are appreciated!

Best regards,

Mark

Trying to tie it all together...
| Indigo | Plex | NAD M33 | Unifi | LG WebOS | Tado | Sonos | SolarEdge | HUE |

Posted on
Sat Apr 04, 2015 9:47 am
DaveL17 offline
User avatar
Posts: 6786
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Activity on computers

That's a really interesting question. I don't know the answer, but there may be something that you can do with Applescript (i.e., set a variable to true/false depending on whether the screen saver is on/off.)

Good luck!

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Sat Apr 04, 2015 10:59 pm
kw123 offline
User avatar
Posts: 8392
Joined: May 12, 2013
Location: Dallas, TX

Re: Activity on computers

Code: Select all
x=int(subprocess.check_output('ioreg -w 0 -c IODisplayWrangler -r IODisplayWrangler'.split()).split("IOPowerManagement")[1].split("DevicePowerState")[1].split(",")[0].strip('"="'))

sets x to:
4=on
1=sleep (not tested)

Karl
=====


some more background:
strip .. split . removes all the other info delivered by ioreg...

paste
Code: Select all
ioreg -w 0 -c IODisplayWrangler -r IODisplayWrangler
into a terminal window and you will get:
Code: Select all
karlMacBook:~ karlwachs$ ioreg -w 0 -c IODisplayWrangler -r IODisplayWrangler
+-o IODisplayWrangler  <class IODisplayWrangler, id 0x100000302, registered, matched, active, busy 0 (0 ms), retain 10>
  | {
  |   "IOProbeScore" = 0
  |   "CFBundleIdentifier" = "com.apple.iokit.IOGraphicsFamily"
  |   "IOMatchCategory" = "IOGraphics"
  |   "IOClass" = "IODisplayWrangler"
  |   "IOProviderClass" = "IOResources"
  |   "IOGeneralInterest" = "IOCommand is not serializable"
  |   "IOGraphicsIgnoreParameters" = {"aupc"=Yes,"auph"=Yes," bpc"=Yes,"aums"=Yes,"aupp"=Yes}
  |   "IOUserClientClass" = "IOAccelerationUserClient"
  |   "IOPowerManagement" = {"CapabilityFlags"=32832,"MaxPowerState"=4,"ActivityTickles"=25659,"DevicePowerState"=4,"IdleTimerPeriod"=224000,"TimeSinceLastTickle"=21,"IdleTimerElapsedTime"=119451,"CurrentPowerState"=4}
  |   "IOGraphicsPrefsParameters" = {"thue"=Yes,"pscn"=Yes,"vbst"=Yes,"tbri"=Yes,"oscn"=Yes,"tsat"=Yes,"cyuv"=268435456}
  |   "IOResourceMatch" = "IOKit"
  | }
  |
  +-o IOAccelerationUserClient  <class IOAccelerationUserClient, id 0x1000003b8, !registered, !matched, active, busy 0, retain 5>

 


where CurrentPowerState =xx in line IOPowerManagement = .. should be the power state of the monitor

Posted on
Sun Apr 05, 2015 8:07 am
kw123 offline
User avatar
Posts: 8392
Joined: May 12, 2013
Location: Dallas, TX

Re: Activity on computers

Here a bit more straight forward including an update of an existing variable "screenSaverState"
Code: Select all
import simplejson as json
import subprocess

# ioreg creates a list of states,  grep selects the wanted line
x=subprocess.Popen('ioreg -w 0 -c IODisplayWrangler -r IODisplayWrangler | grep IOPowerManagement',shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE).communicate()[0]

# split()[1] selects the {"xx"=4,...} string ,   replace() makes it a json compatible string
y=x.split(" = ")[1].replace("=",":")

## this makes z a dict  and z["state"] gives the value wanted.
z=json.loads(y)

# at last update the variable in indigo, must already exist
indigo.variable.updateValue("screenSaverState",str(z['CurrentPowerState']))
put this code into an action of a schedule that runs e.g. once a minute and your variable "screenSaverState" will contain the state of your monitor

Karl

Posted on
Tue Apr 07, 2015 11:43 am
kw123 offline
User avatar
Posts: 8392
Joined: May 12, 2013
Location: Dallas, TX

Re: Activity on computers

get Status of monitor active .. asleep/ off

put the attached code into a schedule and run it every minute. the variable "screenSaverState" is updated and a log file entry is made (if you uncomment that line.)
Code: Select all
import simplejson as json
import subprocess

# ioreg creates a list of states,  grep selects the wanted line .... /usr/sbin/ is needed as the shell has no paths defined.
x=subprocess.Popen('/usr/sbin/ioreg -w 0 -c IODisplayWrangler -r IODisplayWrangler | grep IOPowerManagement',shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE).communicate()[0]

##indigo.server.log(" monitor status:"+str(x))  # for debugging if needed

# split()[1] selects the {"xx"=4,...} string ,   replace() makes it a json compatible string
y=x.split(" = ")[1].replace("=",":")

## this makes z a dict  and z["state"] gives the value wanted.
z=json.loads(y)

# at last update the variable in indigo, if it does not exist, we will create it
try:
    indigo.variable.create("screenSaverState")
except:
   pass
indigo.variable.updateValue("screenSaverState",str(z['CurrentPowerState']))

## uncomment if you like to enter state into logfile
#indigo.server.log(" monitor status:"+str(z['CurrentPowerState']))

this one creates the variable if it does not exists and writes into log file if you want it.

Posted on
Sat Apr 18, 2015 4:59 am
Nine offline
Posts: 78
Joined: Feb 15, 2015
Location: Zurich, Switzerland

Re: Activity on computers

Great code-snipped Karl!

But this does only work on a device Indio running, right? I do have Indio on a macmini with no screen... and would like to check if my MacBook Air or iMac is active. Could the Indigo-Server check these devices over the network?

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 2 guests