I am trying to enumerate the screens via command line on OSX while on the loginscreen (using ssh).
But both [NSScreen screens]
and CGGetActiveDisplays
both return 0 screens. Is there another method of screen enumeration?
Join Stack Overflow to learn, share knowledge, and build your career.
I am trying to enumerate the screens via command line on OSX while on the loginscreen (using ssh).
But both [NSScreen screens]
and CGGetActiveDisplays
both return 0 screens. Is there another method of screen enumeration?
A pre-login agent can enumerate displays using CGGetOnlineDisplayList.
I used the sample Apple code from here.
Modified it to link CoreGraphics, and added the following code to the applicationDidFinishLaunching
method:
CGDirectDisplayID displays[10];
uint32_t numDisplays = 0;
CGGetOnlineDisplayList(10, displays, &numDisplays);
for(uint32_t i = 0; i < numDisplays; i++)
{
[[LogManager sharedManager] logWithFormat:@">>> Found an online display!"];
}
if(numDisplays == 0)
[[LogManager sharedManager] logWithFormat:@"<<<<< No displays!"];
Following the documentation in the sample on how to view the logs, the following is printed on the login screen:
Jul 12 10:03:09 veeboxs-MacBook-Pro PreLoginAgentCocoa[3129] <Info>: Did finish launching begin
Jul 12 10:03:09 veeboxs-MacBook-Pro PreLoginAgentCocoa[3129] <Info>: Showing window with extreme prejudice
Jul 12 10:03:09 veeboxs-MacBook-Pro PreLoginAgentCocoa[3129] <Info>: Did finish launching end
Jul 12 10:03:09 veeboxs-MacBook-Pro PreLoginAgentCocoa[3129] <Info>: >>> Found an online display!
CGGetOnlineDisplayList()
failed to discover displays, according to what OP says.
– hidefromkgb
Jul 13 '17 at 15:04
CGGetOnlineDisplayList()
? If a display is online, it is not necessarily active. – hidefromkgb Jul 11 '17 at 16:22CGDisplayIsActive()
. Also note the multitude of related functions at the bottom of that page. – hidefromkgb Jul 12 '17 at 8:52