How to find out if the screensaver is active / the screen is locked on OSX

Hi,

(I posted this to wxpython-mac, but that is only for porting wxpython
to OSX, so I thought I'd repost here.)

I need to know if the screensaver is active, so I can pause in my
app.

Things I found so far: there seems to be a ScreenSaverEngine, which
seems to
implement a Protocol called ScreenSaverControl, which exports a
screenSaverIsRunning
method return a boolean.

Can I talk to this engine from wxpython using a cocoa binding of some
sorts? I'd like to do this in
a 1-second timer from my main App. Maybe there's an example somewhere?

Thanks.
Antonio

To reply to my own post, this ScreenSaverEngine does not seem to be
running any more
on OSX 10.6, instead someone recommends:

$ osascript -e 'tell application "System Events"' -e 'get running of
screen saver preferences' -e 'end tell'

from the commandline, but I think that is to involving from a WxPython
timer. Maybe
I can talk to the System Events in an easy way?

Thanks,
Antonio

···

On Jan 23, 10:40 pm, Antonio <antonio.gomez.s...@gmail.com> wrote:

Hi,

(I posted this to wxpython-mac, but that is only for porting wxpython
to OSX, so I thought I'd repost here.)

I need to know if the screensaver is active, so I can pause in my
app.

Things I found so far: there seems to be a ScreenSaverEngine, which
seems to
implement a Protocol called ScreenSaverControl, which exports a
screenSaverIsRunning
method return a boolean.

Can I talk to this engine from wxpython using a cocoa binding of some
sorts? I'd like to do this in
a 1-second timer from my main App. Maybe there's an example somewhere?

Thanks.
Antonio

I don't know of any examples of using PyObjC from a wx app, but it may be possible. Using ctypes to call functions in the Carbon library directly is also a possibility.

···

On 1/23/10 1:40 PM, Antonio wrote:

Hi,

(I posted this to wxpython-mac, but that is only for porting wxpython
to OSX, so I thought I'd repost here.)

I need to know if the screensaver is active, so I can pause in my
app.

Things I found so far: there seems to be a ScreenSaverEngine, which
seems to
implement a Protocol called ScreenSaverControl, which exports a
screenSaverIsRunning
method return a boolean.

Can I talk to this engine from wxpython using a cocoa binding of some
sorts? I'd like to do this in
a 1-second timer from my main App. Maybe there's an example somewhere?

--
Robin Dunn
Software Craftsman

There is an appscript module available that will let you interact with AppleScript from Python. http://appscript.sourceforge.net/

···

On 1/23/10 1:47 PM, Antonio wrote:

To reply to my own post, this ScreenSaverEngine does not seem to be
running any more
on OSX 10.6, instead someone recommends:

$ osascript -e 'tell application "System Events"' -e 'get running of
screen saver preferences' -e 'end tell'

from the commandline, but I think that is to involving from a WxPython
timer. Maybe
I can talk to the System Events in an easy way?

--
Robin Dunn
Software Craftsman