Archive for the ‘Code’ Category

Default Folder X 4.3.4 Released

Tuesday, December 1st, 2009

I’ve fixed a number of things in version 4.3.4 of Default Folder X.  If you’re using Default Folder X, you should grab the update – it’s free, and will run more smoothly on your system.  A full list of changes is available on the release page, or you can just download the installer here:

http://www.stclairsoft.com/cgi-bin/dl.cgi?DX

Thanks to everyone for their feedback and assistance with testing!

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Being careful with LSSharedFileListAddObserver

Friday, November 6th, 2009

So, Apple added this cool little capability to the Launch Services API in Leopard: LSSharedFileListAddObserver will call your observer function whenever there are changes in a number of different file lists maintained by Launch Services. One of those lists is the “Recent Documents” list in the Apple Menu. ”Great!” I thought, “I’ll roll this into Default Folder X to ensure that it doesn’t miss any recently used folders.”  It’s a simple API – what could go wrong?  As a long time developer, I should have known better – if you EVER say this (even if you never even say it out loud), you need to poke yourself with something sharp and realize that the consequences will probably hurt quite a bit more than that. “What could go wrong?” indeed.

So yes, here I am apologizing for not having poked myself after I used LSSharedFileListAddObserver without asking more questions – or at least without testing more.  Here’s how Default Folder X ended up using 60% of some users’ CPUs while doing nothing useful:

  1. DFX added itself as an observer for kLSSharedFileListRecentDocumentItems.
  2. The observer function got called by Launch Services because the user double-clicked a document in the Finder.
  3. DFX looked at the list, took the most recent entry in it (the first one), asked Launch Services for the URL of the document, and added the folder enclosing that document to its Recent Folders list.

Pretty simple, right? Yeah, I thought so too. This was tested thoroughly on Snow Leopard and performed fine, and all my Leopard testers reported that it worked well for them too.

So what’s the problem then?  Well, there’s this little “issue”…  If a user has a Windows server mounted on the Desktop, things get a little more interesting.  Normally, when Launch Services calls your observer function, it hands you the file list and you ask for a copy of the list.  The list itself is just a series of ID’s and references – to see what’s in an entry, you have to call LSSharedFileListItemResolve().  And that’s where the interesting part happened.  On Leopard, if the shared file list item lies on a Windows server, the act of calling LSSharedFileListItemResolve actually results in the item being changed, so your observer function gets called again the next time you hit your event loop.  The result of this is that you get called over and over again if you naively use LSSharedFileListItemResolve to get more info about the items that Launch Services is handing you.

So – the warning:  If you use LSSharedFileListAddObserver to watch the list of recent documents, keep a copy of the ID’s from the previous call and ONLY call LSSharedFileListItemResolve if there’s a new ID in the array.  Otherwise do nothing, or work off cached information – otherwise you’ll end up in an infinite loop, sucking down lots of CPU time.  And if you’re doing anything that interacts with the filesystem, make SURE you test with SMB shared volumes too.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Move Items Contextual Menu for Snow Leopard

Wednesday, September 16th, 2009

Contextual menu plugins are dead in Snow Leopard, replaced by the revamped Services system.  A user recently contacted me because he wanted to replicate the “Move Items” contextual menu item he used to use in Leopard.  He had used Automator to create a service, but was having a few problems, namely that Default Folder X wasn’t available when he chose the destination folder.

This got me to open up Automator in Snow Leopard and take a crack at it myself.  In the process, I was reminded how cool Automator is :)   At any rate, here’s the automator script I put together:

So you’re obviously asking: Why go to the trouble of creating variables instead of just using the “Move Finder Items” action by itself?  I’m glad you asked!  The reason is that I want to bring up a file dialog to specify the folder where I want the items to go.  There’s not a clean way to have the “Move Finder Items” do that every time.  You can change its options to “Show this action when the workflow runs” but you still have to click on it every time you use it to ask it to show a file dialog.  If you use Default Folder X to enhance your Open dialogs, it’s faster to just have the dialog pop up and then go where you want to with DFX.

So in the image above, the workflow puts the current Finder selection into the “selection” variable.  Then it uses AppleScript to bring up a file dialog to ask for a folder, which it stores in the “path” variable.  And finally, it uses the Move Finder Items action to do the work.  Not too much more complicated, and it speeds up your workflow considerably if you’ve already got DFX installed so the Open dialogs are smart.

For you automator programmers, note that some of the actions shown in the workflow do not take inputs.  I did this by control-clicking on the action (“Get Value of Variable”, for example) and choosing “Ignore Input” from the contextual menu.  If you don’t do this, Automator will actually add the input from the previous step to the next one, which is definitely not what you want in this case.

Oh, and if you just want the automator workflow file so you can add it to your own system, you can download it here:

http://www.stclairsoft.com/download/MoveItems.zip

If you need more help with Automator and Services, Apple has some good information and tutorials here:

http://www.macosxautomation.com/services/learn/

(Once you’ve gotten through the first few steps of the tutorial, you should be able to just replicate the picture above to make the Move Items service yourself).

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Popping up the Default Folder X menu with a hotkey

Monday, June 16th, 2008

Adam Aaron asked if I could make DFX pop up its menu under the mouse when he pressed a certain key combination. You can actually do this now with a simple AppleScript and one of the numerous macro utilities out there (Adam used QuickSilver to make it work on his machine).

First, write a little AppleScript like so:

tell application "Default Folder X"
ShowMenu
end tell

Then have your macro utility of choice (QuickSilver, iKey, QuicKeys, or whatever) run the script when you hit your favorite key combination, and there you go :-)

(Note: If you’re running Default Folder X with its “Show icons and menus in the Dock” setting turned off, the application target in the AppleScript should be “Default Folder X Helper” instead).

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Adding Default Folder X to Contextual Menus

Tuesday, May 13th, 2008

If you want to include one of Default Folder X’s menus (Favorites, Recent Folders, etc) in a Finder contextual menu, it’s easy to do with Abracode’s free OnMyCommand contextual menu plugin.

To add a DFX Favorite menu, follow these steps:

  1. Download OnMyCommand.
  2. You’ll get a disk image that looks like this. Run the “Install OnMyCommandCM” script and let it relaunch the Finder after it installs the CM plugin.
  3. Open the “OMCEdit” folder and launch OMCEdit. You’ll get a message that it needs to create a new preference file. Tell it to do so.
  4. From the “Command” menu, choose “New”.
  5. Fill in the command fields like this:
  6. Once you save the command, it should appear in your contextual menus like so. Clicking on it will bring up the full Default Folder X hierarchical Favorites menu.

You can do this same thing for other DFX menus by substituting a different name for “Favorite” in the AppleScript command you use in OMCEdit. Valid options are “Disk”, “Favorite”, “Recent”, and “Finder”. Leaving off the ‘named “Favorite”‘ entirely will pop up the entire DFX menu hierarchy as it appears in the menubar.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]