Finding files with Google Desktop on Leopard (or, fun with AppleScript)

Friday, February 08, 2008 at 3:15 PM



Last spring I wrote a blog post about using AppleScript with Google Desktop. It described how you can combine the speed of Google Desktop with the power of AppleScript to search your Mac in a variety of ways.

Recently I was writing some scripts that use Google Desktop to search for files on Leopard and I ran into an issue. It appears that AppleScript on Leopard (Mac OS X 10.5.1) has some problems with the term "file", which is also a type in AppleScript. Google Desktop uses "file" as a type to search for, as in the following example:

search for "Hasselhoff" restrict to file

which should restrict my search to any file containing the term "Hasselhoff". This works great on Tiger, but on Leopard you get:

Google Desktop got an error: Can’t make file into type constant.

Well, according to the AppleScript manual, I should be able to turn the term "file" into its chevron-wrapped type and get the script to compile (you can get more info in Apple's documentation). For Google Desktop, that chevron-wrapped type would be «constant tyreFile».

So we get the ugly, but runnable:

search for "Hasselhoff" restrict to «constant tyreFile»

and when this is compiled Script Editor happily turns this back into:

search for "Hasselhoff" restrict to file

which appears great. The problem is that the next time you compile it you get back to:

Google Desktop got an error: Can’t make file into type constant.

Sigh. Even more depressing is that according to the AppleScript documentation, there is no way to coerce anything useful into a constant, so we can't store «constant tyreFile» as a string and coerce it at runtime. So what is a desperate AppleScripter to do? Luckily we can run another script at runtime, in the same namespace as our tell block, using the "run script" scripting addition from AppleScript's "Standard Additions". Now we can do something like this:

set restrictType to run script "«constant tyreFile»"
search for "Hasselhoff" restrict to
restrictType

It's not super fast, and it certainly isn't pretty, but it will compile and run consistently on both Tiger and Leopard. Here's hoping this will be fixed in the future, but until then, this technique should come in handy for other edgy AppleScript situations.

Developing for MacFUSE

Friday, February 01, 2008 at 9:49 AM



As we recently announced, MacFUSE Core now includes a framework that makes it easy to develop file systems written in Objective-C. I've posted a tutorial that walks you through creating a simple but fun file system using MacFUSE.framework. The file system exports the 11 top-rated YouTube videos with thumbnails and all; you can double-click on them to open up the video in your web browser. This is the same example that I worked through in detail during a recent talk I gave at CocoaHeads. In addition to the talk, there were mind-bending demos of file systems written in Objective-C, such as RunTimeFS and AccessiblityFS. I really enjoyed the CocoaHeads meeting and encourage my fellow Mac developers to attend their local gatherings.

If you have feedback on the tutorial, MacFUSE.framework, or just want to let us know about a cool file system you're working on, feel free to post to the Google Group for MacFUSE.