-
Notifications
You must be signed in to change notification settings - Fork 1
/
QuittyAppDelegate.m
47 lines (36 loc) · 1.23 KB
/
QuittyAppDelegate.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//
// QuittyAppDelegate.m
// Quitty
//
// Created by Daniel Höpfl on 26.01.11.
// Copyright 2011 Daniel Höpfl. All rights reserved.
//
#import "QuittyAppDelegate.h"
@interface QuittyAppDelegate()
- (void) switchHandler:(NSNotification*) notification;
@end
@implementation QuittyAppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
NSNotificationCenter *nc = [[NSWorkspace sharedWorkspace] notificationCenter];
[nc addObserver:self
selector:@selector(switchHandler:)
name:NSWorkspaceSessionDidResignActiveNotification
object:nil];
}
- (void) switchHandler:(NSNotification*) notification
{
BOOL iTunesIsRunning = NO;
NSArray * launchedApplications = [[NSWorkspace sharedWorkspace] launchedApplications];
for (NSDictionary *app in launchedApplications) {
if ([@"com.apple.iTunes" isEqualToString:[app objectForKey:@"NSApplicationBundleIdentifier"]]){
iTunesIsRunning = YES;
break;
}
}
if (iTunesIsRunning) {
NSAppleScript *as = [[[NSAppleScript alloc] initWithSource:@"tell app \"iTunes\" to quit"] autorelease];
NSDictionary *error;
[as executeAndReturnError:&error];
}
}
@end