OS X Dock API? Retrieve OS X active application's icon with badges and other modifications

帅比萌擦擦* 提交于 2020-01-01 18:43:17

问题


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: https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Workspace/introduction.html


回答1:


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];


来源:https://stackoverflow.com/questions/2550782/os-x-dock-api-retrieve-os-x-active-applications-icon-with-badges-and-other-mod

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!