-
Notifications
You must be signed in to change notification settings - Fork 14
/
AMAppDelegate.m
47 lines (36 loc) · 1.21 KB
/
AMAppDelegate.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
//
// AppDelegate.m
// AudioMateLauncher
//
// Created by Ruben Nine on 12/24/12.
// Copyright (c) 2012 Ruben Nine. All rights reserved.
//
#import "AMAppDelegate.h"
@implementation AMAppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Check if main app is already running; if yes, do nothing and terminate helper app
BOOL alreadyRunning = NO;
NSArray *running = [[NSWorkspace sharedWorkspace] runningApplications];
for (NSRunningApplication *app in running)
{
if ([[app bundleIdentifier] isEqualToString:@"com.troikalabs.AudioMate"])
{
alreadyRunning = YES;
}
}
if (!alreadyRunning)
{
NSString *path = [NSBundle mainBundle].bundlePath;
NSMutableArray *pathComponents = [path.pathComponents mutableCopy];
[pathComponents removeLastObject];
[pathComponents removeLastObject];
[pathComponents removeLastObject];
[pathComponents addObject:@"MacOS"];
[pathComponents addObject:@"AudioMate"];
NSString *newPath = [NSString pathWithComponents:pathComponents];
[[NSWorkspace sharedWorkspace] launchApplication:newPath];
}
[NSApp terminate:nil];
}
@end