@@ -30,6 +30,44 @@ find_active_process_name(void)
3030 GetFrontProcess (& psn );
3131 return find_process_name_for_psn (& psn );
3232}
33+
34+ static inline char *
35+ find_process_bundle_id_for_psn (ProcessSerialNumber * psn )
36+ {
37+ CFDictionaryRef process_info_ref = ProcessInformationCopyDictionary (psn , kProcessDictionaryIncludeAllInformationMask );
38+ CFStringRef process_bundle_id_ref = CFDictionaryGetValue (process_info_ref , kCFBundleIdentifierKey );
39+ char * process_bundle_id = copy_cfstring (process_bundle_id_ref );
40+ for (char * s = process_bundle_id ; * s ; ++ s ) * s = tolower (* s );
41+ CFRelease (process_info_ref );
42+ return process_bundle_id ;
43+ }
44+
45+ static inline char *
46+ find_active_process_bundle_id (void )
47+ {
48+ ProcessSerialNumber psn ;
49+ GetFrontProcess (& psn );
50+ return find_process_bundle_id_for_psn (& psn );
51+ }
52+
53+ static inline char *
54+ find_process_bundle_name_for_psn (ProcessSerialNumber * psn )
55+ {
56+ CFDictionaryRef process_info_ref = ProcessInformationCopyDictionary (psn , kProcessDictionaryIncludeAllInformationMask );
57+ CFStringRef process_bundle_name_ref = CFDictionaryGetValue (process_info_ref , kCFBundleNameKey );
58+ char * process_bundle_name = copy_cfstring (process_bundle_name_ref );
59+ for (char * s = process_bundle_name ; * s ; ++ s ) * s = tolower (* s );
60+ CFRelease (process_info_ref );
61+ return process_bundle_name ;
62+ }
63+
64+ static inline char *
65+ find_active_process_bundle_name (void )
66+ {
67+ ProcessSerialNumber psn ;
68+ GetFrontProcess (& psn );
69+ return find_process_bundle_name_for_psn (& psn );
70+ }
3371#pragma clang diagnostic pop
3472
3573static OSStatus
@@ -55,6 +93,20 @@ carbon_event_handler(EventHandlerCallRef ref, EventRef event, void *context)
5593
5694 carbon -> process_name = find_process_name_for_psn (& psn );
5795
96+ if (carbon -> process_bundle_id ) {
97+ free (carbon -> process_bundle_id );
98+ carbon -> process_bundle_id = NULL ;
99+ }
100+
101+ carbon -> process_bundle_id = find_process_bundle_id_for_psn (& psn );
102+
103+ if (carbon -> process_bundle_name ) {
104+ free (carbon -> process_bundle_name );
105+ carbon -> process_bundle_name = NULL ;
106+ }
107+
108+ carbon -> process_bundle_name = find_process_bundle_name_for_psn (& psn );
109+
58110 return noErr ;
59111}
60112
@@ -65,6 +117,8 @@ bool carbon_event_init(struct carbon_event *carbon)
65117 carbon -> type .eventClass = kEventClassApplication ;
66118 carbon -> type .eventKind = kEventAppFrontSwitched ;
67119 carbon -> process_name = find_active_process_name ();
120+ carbon -> process_bundle_id = find_active_process_bundle_id ();
121+ carbon -> process_bundle_name = find_active_process_bundle_name ();
68122
69123 return InstallEventHandler (carbon -> target ,
70124 carbon -> handler ,
0 commit comments