title: Capture Mac screen for multiple users
body: <p>I'm trying to capture the screen on a Mac with a Daemon that runs as root.</p>
  
  <p>The code looks something like this:</p>
  
  <pre><code>activeDisplayID = CGMainDisplayID();
  CGImageRef image = CGDisplayCreateImage(activeDisplayID);
  </code></pre>
  
  <p>I works well but when I switch to another user, I continue to get the screen of the previous user - it is alive so there seem to be some higher meaning with this from Apple.</p>
  
  <p>For some use cases this would be perfect but I would like to capture the screen that's actually being displayed on the monitor.</p>
  
  <p>When the new user logs in, the display id returned from CGMainDisplayID() changes but I get the screen for the first user when I create the image!?</p>
  
  <p>I have to stop the Daemon and start it again to get the screen from a different user. It seems like the Mac OS caches the first display access and keeps giving that to the Daemon.</p>
  
  <p>Is there a way to reset this or some other workaround for this behavior?</p>