views:

485

answers:

2

Due to the new limitations of Kerberos in OS X 10.6, I'm working on a script that offers similar functionality to what used to be available in 10.5. Essentially it parses the klist output to see if your ticket is expiring and displays how long until it expires. If we hit the 10 minute mark, it calls kinit to do a GUI password prompt to ask for your kerberos password. If the ticket is expired it does the same thing.

The script makes sure that kinit is not running before calling it again so we don't have multiple kinit calls, and the script works really great (called out of GeekLog so you can see the status). Problem is this morning my system was giving the spinning beachball when I went to unlock the screen. I am suspecting my script and/or kinit from doing something; the machine was available via ping, but otherwise unresponsive to ssh or AFP.

So what I want to do is detect whether or not the screen is locked or the screensaver is engaged. I've found that on previous versions of OS X, you could grep for ScreenSaverEngine to determine whether it was active or not, but that doesn't seem to be the case any longer.

So how can I determine if the screen is locked or otherwise engaged using commandline tools? If the screen is locked, I want the script to simply exit so it doesn't bother with the klist or try to do a kinit. I'm hoping that will prevent the lockup I experienced this morning. Any ideas?

A: 

Just out of curiosity, have you tried ssh'ing into the OS X machine and compare the process list before/after the screen saver / lock ?

That's what I'd try.

Martín Marconcini
Yeah, I tried that using ps ax|awk '{print $5,$6}' (so that stuff like pid and running time don't make the diff throw false positives) and there is absolutely no change. So there is an existing process that is running that handles this (unlike the ScreenSaverEngine of previous versions that shows up when the screen is locked).
vdanen
A: 

A bit of a kludge but you can easily query the System Events background app via Apple Events to tell if a screen saver is running. For example:

$ osascript -e 'tell application "System Events"' \
>  -e 'get running of screen saver preferences' \
>  -e 'end tell'
false
$ # engage screen saver after starting next command
$ sleep 5; osascript -e 'tell application "System Events"'  -e 'get running of screen saver preferences'  -e 'end tell'
true
$

You probably really need to find out why you're getting the lock up, though.

Ned Deily
Yeah, I wish I knew what was causing the hang. I ended up making an Automator workflow application that would do a yes/no prompt (which is what would execute when the screen was locked) before calling kinit after receiving the "yes" and it locked the system too.This works... but only if the screensaver is running I guess. It doesn't work if the screen is locked (no screensaver) which is the problem I have. Doing a kinit and it expiring at 2am on a locked screen (display put to sleep), would still cause the hang. =(
vdanen