From bdd09cf4f933b455ae8e299d975e16c4e7606624 Mon Sep 17 00:00:00 2001 From: Steve Mokris Date: Thu, 14 Dec 2017 14:25:06 -0500 Subject: [PATCH] Add a warning if the process is not running within a Quartz GUI session. --- GetWindowID.m | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/GetWindowID.m b/GetWindowID.m index 2e1c15a..5ef861d 100644 --- a/GetWindowID.m +++ b/GetWindowID.m @@ -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"];