简体   繁体   English

从cmd + tab获取ProcessList

[英]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属性对应于NSRunningApplicationactivationPolicy属性,而不是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.

相关问题 如何从坞站中删除图标但保留在cmd-tab(可可)中 - How to remove Icon from dock but keep in cmd-Tab (Cocoa) 如何在iPhone手机应用程序的“收藏夹”选项卡之类的按钮中完成操作 - how to get done in button like in favorites tab of iphone phone app UITabBar的Modal Popup项,如Instagram Post Tab项 - Modal Popup from UITabBar Item Like Instagram Post Tab Item 从ViewController中的UITabBar获取选项卡选择事件 - Get Tab Selection Event from UITabBar in a ViewController 阻止在cmd选项卡中显示应用程序(应用程序周期) - prevent an application to be show in the cmd tab (application cycle) iPhone,我想从我的标签栏创建一个弹出菜单,但是他们叫什么,比如复制/粘贴? - iPhone, I want to create a popup menu from my tab bar, but what are they call, like copy / paste? 如何从“常规”>“关于”选项卡中获取模型 - How to get the model from the General>About tab iPhone 如何从标签栏控制器获取“当前”导航控制器 - How to get the 'current' navigation controller from tab bar controller UISearchController之类的Instagram Explore Tab - UISearchController like Instagram Explore Tab iOS导航栏,带有“tab like”功能/按钮 - iOS navigation bar with “tab like” functionality/buttons
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM