Let me explain what I'm trying to do before I get to my question. I'm trying to create a shell script for my Mac, OS 10.5.4, that does the following: -Runs every 20 seconds -Checks to see if a user is logged in and active -Captures a screenshot of that user's desktop and saves it to disk I figure out how to make the script run every 20 seconds by using launchctl along with a plist file. The plist file uses the StartInterval key with a value of 20, thus invoking it every 20 seconds. I loaded the job as root with the command "sudo launchtl load $path_to_plist_file", then "sudo load $name_of_job". I figured out how to capture a screenshot with a script. Since the script is running AS root but it is not grabbing a screenshot FOR root, according to the screencapture man page I have to use the command "sudo launchctl bsexec $PID screencapture..." I have tested this and it works, but it only works if I know the PID for the current, active user. I do not know how to find the PID for the current, active user. As I said above, I would like the script to see first of all IF there is a user logged in with their desktop open. Since I have Fast User Switching enabled, there can be multiple users logged in but not active and the monitor displaying the login window. Also, the script is running as root so I can't use "whoami" or "logname" because they won't tell me anything about which user is using their desktop. Does anyone know how a script can check to see if a user is logged in with their desktop active on the monitor?