OS X Dock API? Retrieve OS X active application

2019-05-30 08:23发布

Is there an API for retrieving the icons of the currently open apps on Mac OS X? I am trying to retrieve all the icons of the active applications along with any badges on top of the application (i.e. number of new messages in mail, or current download rate in Transmission). Is there some sort of Dock API?

The only mention of an OSX API for retrieving information about currently active applications I have been able to find is the Process Manager API, which does not mention the ability to poll the dock or retrieve icon data.

As far as application icons, the only documentation I have found is related to NSWorkspace: http://developer.apple.com/mac/library/documentation/cocoa/Conceptual/Workspace/Workspace.pdf

1条回答
在下西门庆
2楼-- · 2019-05-30 08:58

Looks like Theocacao has a well documented sample of NSWorkspace being used to obtain open applications and retrieve their icons. There isn't any mention of whether this will also retrieve badges/modifications to the application's icon or if there is a way to subscribe to notifications related to updates of the icon.

Retrieving active applications:

NSWorkspace * ws = [NSWorkspace sharedWorkspace];
NSArray * apps = [ws launchedApplications];
NSLog (@"%@", apps);

Retrieving an application's icon:

NSWorkspace * ws    = [NSWorkspace sharedWorkspace];
NSString    * path  = [ws fullPathForApplication:@"Safari"];
NSImage     * icon  = [ws iconForFile: path];
查看更多
登录 后发表回答