-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
66 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// | ||
// windowDetector.m | ||
// windowDetector | ||
// | ||
// Created by Jon Lara Trigo on 28/04/2020. | ||
// Copyright © 2020 Jon Lara Trigo. All rights reserved. | ||
// | ||
|
||
#import "windowDetector.h" | ||
#import <Foundation/Foundation.h> | ||
#import <AppKit/AppKit.h> | ||
|
||
#define NSLog(FORMAT, ...) fprintf(stderr, "%s\n", [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]); | ||
|
||
@implementation windowDetector | ||
|
||
- (id) init | ||
{ | ||
self = [super init]; | ||
if (!self) | ||
return self; | ||
[[[NSWorkspace sharedWorkspace] notificationCenter] | ||
addObserver:self | ||
selector:@selector(getInfo:) | ||
name:NSWorkspaceDidActivateApplicationNotification | ||
object:nil]; | ||
|
||
[[[NSWorkspace sharedWorkspace] notificationCenter] | ||
addObserver:self | ||
selector:@selector(getInfo:) | ||
name:NSWorkspaceDidTerminateApplicationNotification object:nil]; | ||
|
||
return self; | ||
} | ||
|
||
- (void) getInfo:(NSNotification *)d | ||
{ | ||
NSRunningApplication *app = d.userInfo[NSWorkspaceApplicationKey]; | ||
|
||
NSDate * now = [NSDate date]; | ||
NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init]; | ||
[outputFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; | ||
NSString *dateString = [outputFormatter stringFromDate:now]; | ||
|
||
NSLog(@"{\"name\": \"%@\", \"time\": \"%@\", \"bundleIdentifier\": \"%@\",\"launchDate\": \"%@\",\"PID\": \"%d\", \"isTerminated\": %hhd}", [app localizedName], dateString, [app bundleIdentifier], [app launchDate],[app processIdentifier], [app isTerminated]); | ||
} | ||
|
||
int main(int argc, const char * argv[]) { | ||
@autoreleasepool | ||
{ | ||
NSRunLoop *runLoop = NSRunLoop.currentRunLoop; | ||
windowDetector *w = [[windowDetector alloc] init]; | ||
while ([runLoop runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:5]]); | ||
}; | ||
return 0; | ||
|
||
} | ||
@end |