In between midnight summer nights and dark winter days

FolderGlance and Screen Sieve now also on Leopard! Tue, Nov 06 2007 10:41

I got my hands on Leopard last week, and spent the evenings and weekend figuring out why FolderGlance and Screen Sieve wouldn't work. Screen Sieve was easy to fix; a few changes in the way daemonization must be done on Mac OS X 10.5 was pretty much all it took to make Screen Sieve take the plunge and start working on Leopard again. FolderGlance was more difficult, and I'll spend the next few paragraphs looking at why. If you're not interested in that story, you can just grab the updated versions here:

Before going into why FolderGlance doesn't work correctly on Leopard, it is useful to get an idea of how FolderGlance works. The regular Contextual Menu Item plugin approach is based on three functions: CMPluginExamineContext, CMPluginHandleSelection and CMPluginPostMenuCleanup. FolderGlance only makes use of the examine context and post-menu cleanup functions; the handle selection function isn't used.

When FolderGlance is asked to examine the current context, it will build a list of directory contents for the selected folders and files, as well as any custom folders. Instead of adding them to the context menu using AppleEvent descriptors (which is the supported way of doing things, but also very slow as it requires that the entire menu (with submenus!) is created in advance), it will install a number of Carbon event handlers for the current application and input focus targets. These handlers will be called in response to opening menus, populating them, etc.

At least, that was the way things worked prior to Leopard. In Leopard, the Finder context menu changed from having all items in the main context menu, to adding additional items in a "More..." menu. In addition, contextual menu plugins are no longer loaded until that menu is opened. The result is that FolderGlance no longer would get an event telling it to populate a menu, effectively removing it from the More...-context menu as well. Adventurous users will be able to discover that by using the "separate submenu" or "at the bottom" settings in FolderGlance will make the old version of FolderGlance work - at least if you look for FolderGlance items under the Automator submenu!

Unfortunately, there are other issues as well. The biggest showstopper is that using keyboard navigation will cause the Finder to start populating all submenus of the current menu, including ones that haven't been created yet by FolderGlance. This makes FolderGlance go into an indexing-frenzy, which obviously is detrimental to performance and in fact does not work.

The way I solved this in FolderGlance was as follows. Instead of populating submenus in response to the kEventMenuPopulate event, menus are populated in response to the kEventMenuOpening event. In addition, some magic is necessary to determine when to populate on menu open. It is, for instance, not a good idea to populate the Finder's own Open with... menu, as that will work fine the first time, but cause the Finder to crash on subsequent attempts.

Finally, the Finder now also comes with a bug that causes contextual menu plugins to have their examine context function called, but without a corresponding post-menu cleanup call. This call is very important in FolderGlance, as it is responsible for removing the event handlers. To work around this, a dreadful hack that keeps track of the number of menu close-events compared to menu-open events is used. (In case you are wondering, this particular bug only occurs if you open the context menu, start navigating it using the arrow keys, and then close it but without ever opening the More... submenu.)

The upshot of all this, though, is that things now appear to work again. So if you haven't already, get the new version and leave the travesty that are stacks in the Dock behind.



Previous: Mysterious window server hangs Next: FolderGlance, Leopard and the More... menu

About me
My name is Daniel Stødle. I live in Tromsø, Norway, at 69.66° North. By day, I work as a researcher at the Northern Research Institute in Norway; by night, I run my company SCSC. I do most of my development on and for Mac OS X. My research is geared towards interaction with and visualization of geospatial data. Read more on my personal page.

Software

Contact me
E-mail: daniel@scsc.no

Recent posts


2011
Jul 28: Running iTunes in a debugger (gdb)
Jul 25: The /Volumes/MobileBackups directory
Jul 20: FolderGlance 3.0.1 supports Lion
Mar 03: Quick tip: Speeding up Xcode compilations
Mar 02: FolderGlance 3.0
Jan 07: Making Universal Back Button work on 10.6.5 and later

2010
Sep 03: Creating pthreads in C++ using pointers to member functions
May 31: Quickly open URLs in Terminal
May 31: Snow Leopard and automatically submitted Crash Reports
May 27: Universal Back Button released for Mac OS X
May 22: The 22 Megapixel Laptop
Feb 09: FolderGlance on MacUpdate Promo

2009
Sep 28: FolderGlance 2.5.3 is out
Sep 21: FolderGlance 2.5.1 adds features and fixes bugs
Sep 16: FolderGlance 2.5 released!
Sep 10: Intriguing: Snow Leopard ships with the iPhone's multi-touch API built-in
Sep 03: FolderGlance and Snow Leopard
Mar 15: Fixing Keynote '08 and '09 to work with the Scripting Bridge
Feb 26: A website in an image
Feb 09: Display wall multi-touch

2008
Feb 19: Spaces.. Spaces.. Spaces.. retires
Feb 08: How-to: Reverse engineering the Dock to fix Spaces
Jan 25: Interacting with wall-sized displays

2007
Dec 20: Interesting Finder bug
Dec 06: Developing applications for the iPod touch (and the iPhone)
Nov 15: Spaces.. Spaces.. Spaces.. and 10.5.1
Nov 15: Thread creation using pthread_create() on Leopard
Nov 13: Spaces.. Spaces.. Spaces..
Nov 07: FolderGlance, Leopard and the More... menu
Nov 06: FolderGlance and Screen Sieve now also on Leopard!
Sep 16: Mysterious window server hangs

Archive
2007
2008
2009
2010
2011

RSS feed
RSS

Links
SCSC
Blog frontpage