Dynamic Dock Icon

I found code to do this on Windows, and I KNOW there has to be something here for OSX

I need/want to be able to alter the Application Icon being displayed in the DOCK while the application is running…

Either by replacing it on the fly with a “picture” object or drawing on an existing object.

This is above and beyond the red text bubble like you see in MAIL, but more like the Date Icon you see in Calendar

You would use Application.DockItem wouldn’t you? This page reads like you can draw anything you want to your application’s dock icon with the graphics object (more than just the red number indicator.)

That kind of works… you are “drawing” on a 1024 x 1024 image (regardless of what the LR says)
and then that image is downsized to match whatever size your dock requires…
So you have to draw REALLY huge, and hope you don’t lose too much detail when it downsizes…

ie. Textsize for a string would be in the 300 - 600 size range

  dim g as graphics=app.DockItem.Graphics
  g.ForeColor=&cff0000
  g.fillrect 0,0,g.width,g.height
  g.ForeColor=&c0000ff
  g.drawline 0,0,g.Width,g.Height  // this line is too "thin" to appear
  app.DockItem.UpdateNow

[quote=180826:@Dave S]That kind of works… you are “drawing” on a 1024 x 1024 image (regardless of what the LR says)
and then that image is downsized to match whatever size your dock requires…
So you have to draw REALLY huge, and hope you don’t lose too much detail when it downsizes…

ie. Textsize for a string would be in the 300 - 600 size range

dim g as graphics=app.DockItem.Graphics g.ForeColor=&cff0000 g.fillrect 0,0,g.width,g.height g.ForeColor=&c0000ff g.drawline 0,0,g.Width,g.Height // this line is too "thin" to appear app.DockItem.UpdateNow [/quote]

You could try the other way. Draw at 64x64 or close to the screen size, then scale it up to feed to DockItem which in turn will scale it down. But that way you normally should not have lines too thin to render.

Do you actually want to draw the icon or would it be better to just swap it out with existing icons?

I need to draw OVER the existing Icon… The text is too dynamic (and needs to be localized) to pre-create the icons

Where? :wink:

[quote=180826:@Dave S]That kind of works… you are “drawing” on a 1024 x 1024 image (regardless of what the LR says)
and then that image is downsized to match whatever size your dock requires…
So you have to draw REALLY huge, and hope you don’t lose too much detail when it downsizes…

ie. Textsize for a string would be in the 300 - 600 size range

dim g as graphics=app.DockItem.Graphics g.ForeColor=&cff0000 g.fillrect 0,0,g.width,g.height g.ForeColor=&c0000ff g.drawline 0,0,g.Width,g.Height // this line is too "thin" to appear app.DockItem.UpdateNow [/quote]
Fwiw, if you figure out how big your text should be at 128x128, you can just multiply by the difference in size.

dim ratio = g.width / 128 G.fontsize = 12 * ratio
That ratio will also be good for figuring out anything else that needs to scale, and if apple ever returns a different size, it’ll just work. The icon wasn’t always 1024x1024 for instance.