Skip to content

Commit da73187

Browse files
author
kenta.hatano
committed
Optionキーを押しながら切り替えたときは隠す、Commandキーを押しながら選択したときはアプリの場所を表示、他
1 parent 84fa80d commit da73187

3 files changed

Lines changed: 63 additions & 6 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>IDEDidComputeMac32BitWarning</key>
6+
<true/>
7+
</dict>
8+
</plist>

SwitchMenu/AppDelegate.m

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ - (void)changeMenuTitle
126126
default:
127127
break;
128128
}
129+
130+
self.sbItem.toolTip = [NSString stringWithFormat:@"%@ - SwitchMenu", app.localizedName];
129131
break;
130132
}
131133
}
@@ -164,7 +166,10 @@ - (void)createSubmenuOfSwitchMenu {
164166
self.items = [[NSMutableArray alloc] init];
165167
NSFileManager *fileManager = [NSFileManager defaultManager];
166168
NSString *folderPath = [SWITCHMENU_ITEMS_FOLDER_PATH stringByExpandingTildeInPath];
167-
NSArray *menuItems = [fileManager contentsOfDirectoryAtPath:folderPath error:NULL];
169+
NSArray *menuItems = [[fileManager contentsOfDirectoryAtPath:folderPath error:NULL] sortedArrayUsingComparator:^NSComparisonResult(NSString *obj1, NSString * obj2) {
170+
NSStringCompareOptions compareOptions = (NSCaseInsensitiveSearch);
171+
return [obj1 compare:obj2 options:compareOptions];
172+
}];
168173
NSInteger tag = 0;
169174
if (menuItems && [menuItems count] > 0) {
170175
for (NSString *fileName in menuItems) {
@@ -299,7 +304,11 @@ - (void)createSubmenuOfSwitchMenu {
299304
}
300305

301306
if (self.iShowNumberOfWindows > 0) {
302-
title = [NSString stringWithFormat:@"%@ (%ld)",title,numWindows];
307+
if (app.isHidden) {
308+
title = [NSString stringWithFormat:@"%@ (-)",title];
309+
} else {
310+
title = [NSString stringWithFormat:@"%@ (%ld)",title,numWindows];
311+
}
303312
}
304313

305314
NSMenuItem *item = [[NSMenuItem alloc] init];
@@ -340,7 +349,7 @@ - (void)createSubmenuOfSwitchMenu {
340349

341350
NSMutableString *tooltip = [[NSMutableString alloc] init];
342351
[tooltip appendFormat:@"Full Path:\n%@\n",[app.bundleURL path]];
343-
[tooltip appendFormat:@"\nBundle Identifier:\n%@\n",app.bundleIdentifier];
352+
// [tooltip appendFormat:@"\nBundle Identifier:\n%@\n",app.bundleIdentifier];
344353
if (app.launchDate) {
345354
[tooltip appendFormat:@"\nLaunch Date/Time:\n%@\n",app.launchDate];
346355
} else {
@@ -381,11 +390,45 @@ - (void)createSubmenuOfSwitchMenu {
381390
}
382391

383392
- (void)menuSelected:(id)sender {
393+
NSUInteger modifierFlags = [NSEvent modifierFlags];
394+
384395
NSMenuItem *item = sender;
385396
NSInteger tag = item.tag;
386397

387398
NSRunningApplication *app = [self.apps objectAtIndex:tag];
388-
[app activateWithOptions:NSApplicationActivateIgnoringOtherApps];
399+
if ((modifierFlags & NSAlternateKeyMask) && (modifierFlags & NSCommandKeyMask)) {
400+
[app activateWithOptions:NSApplicationActivateIgnoringOtherApps];
401+
402+
for (NSRunningApplication *anApp in self.apps) {
403+
if (![anApp isEqual:app]) {
404+
[anApp hide];
405+
}
406+
}
407+
} else if (modifierFlags & NSAlternateKeyMask) {
408+
NSRunningApplication *currentApp = [NSRunningApplication currentApplication];
409+
410+
for (NSRunningApplication *anApp in self.apps) {
411+
if (anApp.ownsMenuBar) {
412+
currentApp = anApp;
413+
break;
414+
}
415+
}
416+
417+
[app activateWithOptions:NSApplicationActivateIgnoringOtherApps];
418+
[currentApp hide];
419+
} else if (modifierFlags & NSCommandKeyMask) {
420+
[[NSWorkspace sharedWorkspace] selectFile:[app.bundleURL path]
421+
inFileViewerRootedAtPath:[[app.bundleURL path] stringByDeletingLastPathComponent]];
422+
} else {
423+
[app activateWithOptions:NSApplicationActivateIgnoringOtherApps];
424+
}
425+
426+
if (modifierFlags & NSControlKeyMask) {
427+
NSTask *task = [[NSTask alloc] init];
428+
task.launchPath = @"/usr/bin/open";
429+
task.arguments = @[@"-a", @"mission control", @"--args", @"2"];
430+
[task launch];
431+
}
389432
}
390433

391434
+ (NSImage *)resizeImage:(NSImage *)image small:(BOOL)small
@@ -552,11 +595,17 @@ - (IBAction)openSwitchMenuItemsFolder:(id)sender {
552595
}
553596

554597
- (IBAction)selectSwitchMenuFolderItem:(id)sender {
555-
NSString *folderPath = [SWITCHMENU_ITEMS_FOLDER_PATH stringByExpandingTildeInPath];
598+
NSUInteger modifierFlags = [NSEvent modifierFlags];
556599

557600
NSInteger tag = ((NSMenuItem *)sender).tag;
558601
NSString *filePath = self.items[tag];
559-
[[NSWorkspace sharedWorkspace] openFile:filePath];
602+
603+
if (modifierFlags & NSCommandKeyMask) {
604+
[[NSWorkspace sharedWorkspace] selectFile:filePath
605+
inFileViewerRootedAtPath:[filePath stringByDeletingLastPathComponent]];
606+
} else {
607+
[[NSWorkspace sharedWorkspace] openFile:filePath];
608+
}
560609
}
561610

562611

0 commit comments

Comments
 (0)