问题
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