9

Starting in OS X 10.8 Mountain Lion, Safari creates a dynamic icon while downloading a file, as shown below:

: enter image description here

The progress bar shows the progress, and clicking the upper-left close button tells Safari to stop downloading.

Is there a way for a 3rd party app to create this kind of icon?

I guess there's no App Store-compatible way to do this, but I'm curious how to do that / how Safari does it just for the sake of interest.

Yuji
  • 34,103
  • 3
  • 70
  • 88

1 Answers1

0

I think it's part of NSFileWrapper and you might be able to do it with the App Store. I don't know.

NSFileWrapper *fw = [[NSFileWrapper alloc] initWithURL:fileURL,
                    // don't memory map, we only want to change the icon
                                               options:NSFileWrapperReadingWithoutMapping 
                                                 error:NULL];

[fw setIcon:updatedIcon];

Note that icon and setIcon are part of the ApplicationKit category, not the main NSFileWrapper implementation in Foundation: https://developer.apple.com/library/mac/#documentation/AppKit/Reference/NSFileWrapper_AppKitAdditions/NSFileWrapperApplicationKitAdditions.html

Edit: That's how you could have a progress bar. To make the close button you'd need an NSView reference to the icon, like you can do with dock icons.

Edit 2: The WebKit browser does this too (not just Safari) so if you dug through the source you'd probably be able to find it.

Edit 3: I think it's done automatically by NSURLDownload. You could use that style yourself if you made a fake download that was really generating the downloaded content on the fly. I don't believe it's possible to make an arbitrary clickable icon, though.

ddr
  • 201
  • 1
  • 7