[英]Get the ProcessList like from cmd+tab
I want to get the applications from the cmd+tab menu in OS X. The best way I got now is to associate this with a AppleScript call with the following: 我想从OS X的cmd + tab菜单中获取应用程序。我现在最好的方法是将其与AppleScript调用关联,并具有以下内容:
NSDictionary *errorDict;
NSAppleEventDescriptor *returnValue;
NSString *appleScriptText = @"tell application \"System Events\" to get name of (processes where background only is false)";
NSAppleScript *script = [[NSAppleScript alloc] initWithSource:appleScriptText];
Then loop through the stuff coming back from it and to match it to the [[NSWorkspace sharedWorkspace] runningApplications]
but this seems a little bit too weird to get this task done. 然后遍历从中返回的内容,并将其与[[NSWorkspace sharedWorkspace] runningApplications]
相匹配,但这似乎有点怪异,无法完成此任务。
So my question here: is there a way that is not so quirky like this one? 所以我在这里的问题是:有没有一种方法不像这个方法那么古怪?
I am really tense for the answers. 我真的很紧张的答案。
Given that you're already familiar with -[NSWorkspace runningApplications]
, why don't you just iterate over those and check which ones meet your criteria? 鉴于您已经熟悉-[NSWorkspace runningApplications]
,为什么不仅仅遍历这些并检查哪些符合您的条件? The background only
property corresponds to NSRunningApplication
's activationPolicy
property being something other than NSApplicationActivationPolicyRegular
. background only
属性对应于NSRunningApplication
的activationPolicy
属性,而不是NSApplicationActivationPolicyRegular
。
So, something like (not tested): 因此,类似(未经测试)的内容:
NSArray* apps = [[NSWorkspace sharedWorkspace] runningApplications];
NSIndexSet* indexes = [apps indexesOfObjectsPassingTest:^BOOL(id obj, NSUInteger idx, BOOL *stop){
return [obj activationPolicy] == NSApplicationActivationPolicyRegular;
}];
NSArray* names = [[apps objectsAtIndexes:indexes] valueForKey:@"localizedName"];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.