On Mac OS X Snow Leopard with fast user switching enabled, is there an API to detect whether or not my application is running in the active user session? I.e. the session currently attached to screen and keyboard.
Either Objective-C or C++ is fine.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I avoided using User Switch Notifications and instead have found two other possibilities:
Use
CGMainDisplayID()from Core Graphics. Store the main display ID when your app first starts and keep polling it. It will change to a different display ID when switching to another user. Problem with this is it may also change for other reasons e.g. changing which display is the primary display in a multi-screen setup.Use
CGSessionCopyCurrentDictionary()also from Core Graphics, and retrieve thekCGSessionOnConsoleKeyBoolean value from the dictionary. This indicates whether your user session is attached to console.Both of these require polling but this is fine for my purposes. User Switch Notifications would be a better choice if you need to be event-driven.