Oh Gee. It has been forever since I blogged on here. Is anyone still listening?
Someone emailed me recently to ask how Dropzone tracks the dock icon and how can they do something similar with their own Cocoa app.
My reply is below:
You can poll the accessibility API to query the position of the dock element and then set the window frame to this frame.
This app is invaluable for figuring out the correct accessibility element.
This class will help with the accessibility stuff.
I warn you though, once you start down the road of doing horrible hacks like this there is no turning back and you will need 100s more hacks to maintain the initial hack. It took me months of hard work to make the dock tracking system work well and it still has to use a separate process and constantly takes up CPU to poll the API as there is no notification for when the dock tile size changes.
I STRONGLY urge you to find another way to do whatever you are trying to do that does not require a window over the dock icon.
It got me thinking how clever I thought I was when got the dock tracking system Dropzone uses working. It’s a horribly complicated system involving all kinds of hacks and workarounds, all to give me dragging notifications on the dock icon so I could show the grid of actions. This is something Apple never intended apps in the dock to be able to do.
One example of the kinds of extra hacks it leads to is that if you hit F11 it shifts the hidden window off screen, and dock dragging no longer works. This is annoying for a user if they want to expose the desktop and then drag something onto Dropzone. I can get around this by recreating the window when a show desktop is detected, but then I need a way to detect show desktop activation and there is no API for this either…
If you’re thinking of making an app that does hacks like Dropzone, change your mind and don’t. It leads to inflexible and unmaintainable code that is subject to break at any moment.
Compare Dropzone with more standard, single windowed apps like Things and NetNewsWire. I don’t think they have an easy job either, but at least they aren’t trying to interface with integral parts of OS X like the dock where there is no API and things are liable to break next OS update. It’s fun and novel to break all the rules, but in the end, you won’t feel so great about your app. Trust me. Been there.
People have been asking me if I’ve given up on Dropzone. No I haven’t give up and I’m still selling a few licenses a day which I’m really thrilled about. Thank you all.
Part of the reason I haven’t updated Dropzone in a while is that it’s already doing everything I need.
The other reason is that I’m hard at work developing a new app! This will be a slightly more conventional app than Dropzone – It’s a private social network for sharing links, messages and files using Dropbox as the backend. It’s in still in alpha at the moment, but it’s coming along well and I’m hoping to do a big open beta in month or so to get feedback from a wider audience.
An awesome song and video by a great New Zealand artist. Also… Broken Machine… get it?