May 16 2008

Login Screenshot Challenge - Part 3

Published by john at 7:02 am under System

  
  

As explained on the previous post, no doubt there is a means to capture a screenshot of the login screen, including all available user names. The question is, how to get there from here? Brett on the Cocoa developer mailing list provided a link to OpenGLScreenSnapshot, which is a Mac OS X application that demonstrates how to use OpenGL to grab a snaphost of the screen and save it to an image.

The example is an Xcode project which is easily imported and ran from with Xcode. The only problem is that the short example uses a menu to invoke the screencapture, so there is no means to logout and invoke the application.

I imagine the code change to make this an application that can be run from a terminal (at which point it could be run in the background using sleep) is trivial. However, problem is, I haven’t spent any time working with Xcode so it may take some time to figure this out.

Needless to say, it’s been an interesting challenge to try and capture the login screen. As I mentioned before, I think we’re 99% of the way there and if anyone can take the above example and make a command line version of the application, who knows, maybe that will bring this thing full circle.

It’s been a great diversion. So what’s the next challenge we can take on ?

Technorati Tags: ,

6 Responses to “Login Screenshot Challenge - Part 3”

  1. alon 16 May 2008 at 4:05 pm

    Spoke with my OS X guru, and he offers this (for 10.5):

    you have to launch screencapture in the same security context as the loginwindow app in order to get the framebuffer contents

    (me) so what exactly does context mean in this context?

    PID=`ps -ax | grep loginwindow.app | grep -v grep | awk ‘{print $1}’`
    sudo launchctl bsexec $PID screencapture /path/to/screencap.png

    (me) so ARD is doing that behind the scenes?

    launchctl’s bsexec command executes whatever you give to it in the same security context, or “Mach bootstrap namespace hierarchy” as the man page puts it

    we decided that a logout hook script that loops until the loginwindow is up, then grabs the loginwindow PID and uses it with the launchctl bsexec to run screencapture might be best. Will let you know if I can get that working.

  2. johnon 16 May 2008 at 4:11 pm

    Al, that is way cool, thanks so much for keeping on this and thanks to your OS X guru for the helping out here.

    This is not unlike one of those thorny programming conundrums, you know there’s a way to do it, and you can’t stop until you figure it out.

    I look forward to seeing what you come up with!

    John

  3. alon 19 May 2008 at 1:30 pm

    Latest update- tried with a logout hook, but couldn’t get it to actually get to the loginwindow before it took the screencap.

    So now I’m trying to use Lingon to set up Users Daemon running this shell script:

    #! /binbash
    sleep 90 # give the loginwindow 90 seconds to start
    logger -t screencap_script “done sleeping” #logging
    PID=`ps -ax | grep loginwindow.app | grep -v grep | awk ‘{print $1}’`
    logger -t screencap_script “got the PID “$PID
    launchctl bsexec $PID screencapture /Users/ladmin/Desktop/screencap.png
    logger -t screencap_script “screencapture should now be done.”hs-rm190-002540:Sh

    Aaaaannnnnddddd- it worked!

    It’s a little annoying that I’m having to restart to fire it off, but at least it is working.

    In Lingon 2.1 (this is only tested for Leopard) you click the new button, choose User Daemon, make up a name for it (part 1), point it at the script from above (part 2), check “Run it when it is loaded by the system (at startup or login)”, click the save button (authenticate with an admin account) and restart.

  4. alon 19 May 2008 at 1:44 pm

    last second thoughts about my last post:

    you can shorten the sleep time, just make sure it’s long enough for the loginwindow to come up.

    the logger lines can be removed or commented out, they were just for testing to see how far things were getting when it wasn’t working.

    in Lingon, you could set a specific time for the screenshot, then log out and wait instead of restarting… not a lot better, and maybe worse since if you take too long to log out it’ll mess up, and if you set the time too far ahead you have to wait almost as long as if you had restarted (You wouldn’t check the Run it when… box, instead check the At a specific date and set accordingly.)

    Finally, you could have it run every minute, and change the file name (screencapture /path/to/`date “+H;M”`.png where the back ticks ` around the date command tells the shell to run that and substitute the result, you would end up with a timestamped screenshot every minute until you disabled it in Lingon… still pretty messy, the restart doesn’t seem all that bad. ;-)

  5. johnon 19 May 2008 at 4:21 pm

    Al, so what are all the steps needed to run this? I’m not familiar with Lingon, does this need to be downloaded/installed? Any other non-default apps needed?

    Thanks, I’m looking forward to trying it!

  6. Benon 04 Jun 2008 at 8:18 pm

    What about using SSH to log in to a computer that’s on the login screen and then using /usr/sbin/screencapture -o /tmp/ss.jpg or something? Haven’t tried this, so I can’t stand behind it, it’s just the first thing I think of.

Trackback URI | Comments RSS

Leave a Reply