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?

Noitidart
  • 35,443
  • 37
  • 154
  • 323

2 Answers2

4

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
  • 83,389
  • 16
  • 128
  • 151
  • 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. =( –  Sep 08 '09 at 01:40
  • Does this cover if station is locked to? Like does the `get running of screen saver preferences` return true if the station is locked? – Noitidart Dec 16 '14 at 22:24
  • 1
    @Noitidart, you could try it yourself and see. If you mean using a screen saver that requires a password to unlike, it appears to work (tried with OS X Yosemite). – Ned Deily Dec 17 '14 at 02:25
  • Thanks very much for the test. I tested it myself and it works when screen saver comes on. However there is no difference when locked. I have set my script to log every 5sec. my screen saver comes on after 1min, at which point this turns true. i set for lock after 1more min then the workstation locks, it still remains true. after i move the mouse and its now on the lock screen, it still remains true. :( Any ideas on how to detect if locked via script? :( – Noitidart Dec 17 '14 at 02:55
  • You should probably open a new question on that. Someone may know. – Ned Deily Dec 17 '14 at 03:16
0

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.

Martin Marconcini
  • 26,875
  • 19
  • 106
  • 144
  • 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). –  Sep 07 '09 at 17:57