May 14 2008

Login Screenshot Challenge - Part 2

Published by john at 6:21 am under System

  
  

In Part 1 of this series I described my attempts to get a screenshot of the login screen on Mac OS X. The attempts included using hotkeys, Grab application, fast user switching and putting the system to sleep and using the terminal utility ’screencapture.’ All to no avail. The real challenge at hand is that I am looking to accomplish this feat from just one Mac system.

There were several ideas shared by others, including using cron, apple remote desktop and ssh. Again, good intentions, however, no luck.

I was able to dig up one approach that get that gets us 99% of the way there. From a terminal, I can enter the following, where I specify the login name using the switchToUserID parameter:

/System/Library/CoreServices/”Menu Extras”/User.menu/Contents/Resources/CGSession -switchToUserID `id -u root`.

The last parameter `id -u root` uses the terminal command id to convert a user name to a number. Upon running this command, a login window is popped up for the login id specified, see the figure below.

If I change the login id to another user, the login window changes as well:

The 1% that remains is that what I really hope to capture is the login window where all available login ids are shown.

There is a related command (below) that displays the login window I am after, however, this brings me back to the same problem I started with, that is, no means to get a screenshot.

/System/Library/CoreServices/”Menu Extras”/User.menu/Contents/Resources/CGSession -suspend

With some further digging I was able to successfully get the screenshot that I’m after with a couple of approaches:

  1. Using a screen recording program such as ScreenFlow: enable fast user switching, start the recording and select the login window option from the fast user switching dialog. This will capture the sequence of events including the elusive login window.
  2. I also found a few screenshot applications that can successfully capture the login window while running in the background. For example, Christian at MonkeyBread Software wrote a freeware application in REALbasic TimedScreenshot (here’s the source code) that will capture the screenshot I am after:

So, it’s obvious we can get there from here. The question that remains is, what system level API/library can we call to make this happen?

Ideally I’d like to have a very simple application, written in as few lines of code as possible, using tools that are freely available (e.g. Xcode or even better, just terminal commands). If this involves running a program in the background using a terminal command such as sleep (as I did with screencapture in the previous post), that works for me.

Any developers (Cocoa or otherwise) who can take this challenge the last mile?

Technorati Tags: ,

3 Responses to “Login Screenshot Challenge - Part 2”

  1. alon 15 May 2008 at 4:28 pm

    Actually, the Apple Remote Desktop Send Unix Command as root worked great using screencapture /Users/youUserName/Desktop/loginwindowshot.png as long as you don’t mind using two Macs and a non-free application.

    It left a perfect loginwindowshot.png on your desktop, with or without the already logged in indicator depending on how you choose to get to the loginwindow. Which is why it seems so odd that attempts using ssh, cron, and launchd using the same shell command don’t work once they are running as root.

    I’ve looked at the source for TimedScreenShot, and unfortunately the magic happens in a call to what I assume is a RealBasic function, so it’s still hard to see what’s happening.

  2. Geotopiaon 09 Jun 2008 at 7:13 am

    Hey, I might be working out of the parameters you are suggesting, but hey, I had a screen shot within 5 seconds (no joke). I have Timbuktu running on all my machines and it would appear that it loads right after the kernel and before logind because if you remotely connect and log out of a machine, you can remotely access the login. From the remote machine you can then do a CMD-SHFT-4 to grab the screen. I’d upload proof if I had a URL for an http://FTP...

  3. johnon 09 Jun 2008 at 7:19 am

    There have been a lot of good suggestions/options when one has access to two Mac systems. However, the trick here is that I am attempting to get a screenshot without the need for a second machine. It’s proving to be quite the challenge….

Trackback URI | Comments RSS

Leave a Reply