Skip to content

Commit

Permalink
not relaunching already open apps
Browse files Browse the repository at this point in the history
  • Loading branch information
flyingmachine committed Sep 2, 2012
1 parent 211fae4 commit 12f45ab
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions WorkMode/AppGroupController.m
Expand Up @@ -38,7 +38,6 @@ - (void) addApps:(NSArray *)appsToAdd {
[[appGroup valueForKey:@"apps"] addObject: app];
}
}
NSLog(@"add apps");
[iconListView showAppIcons];
[[NSNotificationCenter defaultCenter] postNotificationName:@"addApp" object:self userInfo:NULL];
}
Expand All @@ -48,9 +47,22 @@ - (void) removeAppGroup:(id)sender {
}

- (void) launchApps {
NSMutableArray *openApps = [[NSMutableArray alloc] init];

for (NSRunningApplication *runningApp in[[NSWorkspace sharedWorkspace] runningApplications]) {
if ([runningApp bundleURL]) {
[openApps addObject:[[runningApp bundleURL] path]];
}
}

NSLog(@"open apps: %@", openApps);

for (NSString *app in [appGroup valueForKey:@"apps"]) {
[[NSWorkspace sharedWorkspace] launchApplication:app];
if (![openApps containsObject:app]) {
[[NSWorkspace sharedWorkspace] launchApplication:app];
}
}

[[NSNotificationCenter defaultCenter] postNotificationName:@"appsLaunched" object:self userInfo:NULL];

// for (NSRunningApplication *runningApp in [[NSWorkspace sharedWorkspace] runningApplications]) {
Expand All @@ -75,7 +87,7 @@ - (void) launchApps {
}

- (void) closeApps {
NSMutableArray *appsToClose = [[NSMutableArray alloc] initWithArray:@[]];
NSMutableArray *appsToClose = [[NSMutableArray alloc] init];
NSDictionary *info;
OSErr err = NO;
ProcessSerialNumber psn = {0, kNoProcess};
Expand All @@ -86,15 +98,13 @@ - (void) closeApps {
if (!err)
{
info = (__bridge NSDictionary *)ProcessInformationCopyDictionary(&psn, kProcessDictionaryIncludeAllInformationMask);
NSLog(@"%@", info);
NSString *bundlePath = (NSString *)[info valueForKey:@"BundlePath"];
if (
[[info valueForKey:@"LSUIElement"] intValue] != 1 &&
bundlePath &&
![bundlePath hasPrefix:@"/System"] &&
![[appGroup valueForKey:@"apps"] containsObject:bundlePath]
) {
NSLog(@"lsuielement: %@", [info valueForKey:@"LSUIElement"]);

[appsToClose addObject:bundlePath];
}
Expand Down

0 comments on commit 12f45ab

Please sign in to comment.