Skip to content

Commit

Permalink
Add a warning if the process is not running within a Quartz GUI session.
Browse files Browse the repository at this point in the history
  • Loading branch information
smokris committed Dec 14, 2017
1 parent 10a8300 commit bdd09cf
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions GetWindowID.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,20 @@ int main(int argc, char **argv)
return -1;
}

CFDictionaryRef session = CGSessionCopyCurrentDictionary();
if (!session)
fprintf(stderr,
"Warning: %s is not running within a Quartz GUI session,\n"
"so it won't be able to retrieve information on any windows.\n"
"\n"
"If you're using continuous integration, consider launching\n"
"your agent as a GUI process (an `.app` bundle started via\n"
"System Preferences > Users & Group > Login Items)\n"
"instead of using a LaunchDaemon or LaunchAgent.",
argv[0]);
else
CFRelease(session);

NSString *requestedApp = @(argv[1]);
NSString *requestedWindow = @(argv[2]);
bool showList = [requestedWindow isEqualToString:@"--list"];
Expand Down

0 comments on commit bdd09cf

Please sign in to comment.