Search code examples
swiftmacoscocoansdocktile

Swift - How can I get another application's NSDockTile object in Swift?


How can I get another application's NSDockTile object in Swift?

My thoughts were I could get an array of NSRunningApplications and access the NSDockTile from there but I can only get the NSDockTile from NSApplication. So I guess another, better question, is there a way to cast a NSRunningApplication to an NSApplication or make an NSApplication object from another app's BundleIdentifier or something?

I apologize in advance for any stupidity as I am new to Swift and Cocoa applications.


Solution

  • I doubt there's any (sanctioned) way to do this. The dock tiles of other applications belong to those applications, and I can't ever imagine a reason Apple would provide a means for providing access to it from another application, given the obvious potential for abuse.

    Also, NSApplication and NSRunningApplication are completely different objects. There is no relationship between the two, and trying to cast one reference to the other class will most certainly end in heartache.

    NSApplication is, for all intents and purposes, your application. It's the foundation for the application that's executing and contains methods to run and control your application, dispatch events, put up modal dialogs, and so on.

    NSRunningApplication is a lightweight object that provides some useful information about another application that's running alongside yours. But it is not in any way directly connected with, nor can it control (except as provided), the other app.