Receiving Apple infrared remote control events

Tuesday, April 08, 2008 at 3:42 PM



Most Mac models today ship with a six-button remote control and matching built-in infrared receiver. The remote control's primary purpose is to drive Apple's Front Row media application.

But maybe you'd like to use the remote for your own experiments. There are several software approaches to obtaining remote-button-press information. One of them is to communicate with Mac OS X's in-kernel infrared driver, which is implemented by the AppleIRController kernel extension. The I/O Kit layer in Mac OS X, which we would use for this kind of communication, is particularly powerful and flexible when it comes to allowing user-space access to hardware. So this approach is quite nice.

iremoted is a command-line program that uses I/O Kit interfaces to talk to the infrared driver and prints information about button presses and releases as they occur. I recently overhauled iremoted for Leopard, and the new version should work on both Tiger and Leopard. Moreover, the source for iremoted is now also available.

Enjoy talking to the remote control!

New frontiers with Google Data APIs and Objective-C

Thursday, March 20, 2008 at 11:54 AM



I work on Mac client software because I enjoy the compile-link-run cycle that is central to crafting great experiences for users. But we live in a client-server world, and Google has world-class servers and web applications. That's why Google Data APIs are so cool if you develop Mac software: you don't need to build your own server farms and write your own web interfaces. Just let your software talk directly to Google's servers.

With the recent release of the Google Contacts Data API and the YouTube API for browsing and uploading, developers now have two more ways to reach users. Today's release of version 1.4 of the GData Objective-C Client Library adds support for these new APIs. Any Mac program that creates video can easily let users upload the video to a YouTube account. Mac software can also now enable users to access or edit their Google account contacts.

It's easy and natural for Cocoa programmers to use the library. This code snippet shows how get the names of all contacts in a user's Gmail account address book:

#import "GData/GDataContacts.h"

- (void)fetchContacts {
GDataServiceGoogleContact *service =
[[GDataServiceGoogleContact alloc] init];
[service setUserCredentialsWithUsername:@"myaccount@gmail.com"
password:@"mypassword"];
NSURL *feedURL =
[NSURL URLWithString:kGDataGoogleContactDefaultBaseFeed];

[service fetchContactFeedWithURL:feedURL
delegate:self
didFinishSelector:@selector(ticket:finishedWithContactFeed:)
didFailSelector:@selector(ticket:failedWithError:)];
}

- (void)ticket:(GDataServiceTicket *)ticket
finishedWithContactFeed:(GDataFeedContact *)feed {

NSArray *names =
[feed valueForKeyPath:@"entries.title.stringValue"];
}

- (void)ticket:(GDataServiceTicket *)ticket
failedWithError:(NSError *)error {
NSLog(@"%@", error);
}

Uploading video takes just a bit more effort, because YouTube's API requires metadata describing the video along with the video data itself. The Objective-C GData Library includes sample code showing how to do these and other common tasks with the APIs.

And one more thing...

The source code for the GData Objective-C Client Library is now compatible with the iPhone SDK as well. Perhaps you want your iPhone software to send photos to a Picasa Web Albums account, or keep a journal of phone calls automatically in Blogger. Maybe your iPhone application accesses a database of information from a Google Spreadsheet or from Google Base. With the Google Data APIs Objective-C Client Library, creating software for these tasks is straightforward.

If you are writing iPhone software, just drag the "GData Sources" group folder from the GData project file into your iPhone project, and use the GData APIs as you would when writing a Mac application. The Objective-C Client Library is an open-source project, so you can find links to the sources and documentation on the project page.

Macworld: Another Look Inside

Thursday, March 13, 2008 at 9:22 AM

By Mark Sabec, Associate Product Marketing Manager

This year at Macworld we asked visitors to our booth to talk about what they do online and the Google products they use. The people who participated were anything but camera-shy, and they were all such good sports that we are happy to give them a little YouTube fame. Enjoy the video, and please stop by to see us at Macworld next year!


A File System Change Logger for Leopard

Tuesday, March 11, 2008 at 12:07 PM



When you use Mac OS X, you frequently access files and folders. But you might not realize how often you are creating and modifying files and folders. Developers, power users, and even curious regular users have long been interested in observing and understanding file system changes. This desire might be for security reasons, analyzing software, troubleshooting, or just out of plain old curiosity. In any case, being able to see how files are changing on your machine in real time is a powerful capability.

About three years ago, Apple released Mac OS X Tiger. One major feature of Tiger was the Spotlight search technology, and one of Spotlight's lowest-level building blocks is a kernel-level file system event notification mechanism called fsevents. Spotlight relies upon this mechanism to know about file system changes in real time. Soon after Tiger's release, I released fslogger, a program that subscribes to the fsevents mechanism and displays file system change notifications as they arrive from the kernel. fslogger went on to be quite a popular tool in some circles.

In Mac OS X Leopard, the fsevents mechanism is used for more than just Spotlight. Apple even added the FSEvents API as a way for your applications to ask for notification when contents of a directory hierarchy are modified. (Being directory-level, FSEvents API notifications aren't as granular as directly using fsevents, like fslogger does, but then direct use of fsevents isn't without caveats either.) All said, it can indeed be greatly useful during experimentation to be able to retrieve complete, unfiltered fsevents data from the kernel.

Here's an excerpt from fslogger's output.

$ sudo ./fslogger
...
=> received 90 bytes
# Event
type = FSE_STAT_CHANGED
pid = 13 (syslogd)
# Details
# type len data
FSE_ARG_STRING 24 string = /private/var/log/asl.db
FSE_ARG_DEV 4 dev = 0xe000002 (major 14, minor 2)
FSE_ARG_INO 4 ino = 4277280
FSE_ARG_MODE 4 mode = -rw------- (0x008180, vnode type VREG)
FSE_ARG_UID 4 uid = 0 (root)
FSE_ARG_GID 4 gid = 0 (wheel)
FSE_ARG_INT64 8 tstamp = 25511051709692
FSE_ARG_DONE (0xb33f)
...

I had to make some changes to fslogger to make it compatible with Leopard. Here's the new version that works with Leopard. Source code is also available.

Google Gadgets: Nine New Languages

Wednesday, March 05, 2008 at 10:53 AM



In November we announced Google Gadgets for the Mac. Today we're thrilled to follow up with its release in nine more languages. For the linguistically curious, we're now shipping in English (US and UK), French, Italian, German, Spanish, Dutch, Japanese, and Simplified and Traditional Chinese.


Google Gadgets for the Mac lets you choose from the many hundreds of gadgets that developers have created. As before, your Google Gadgets will run seamlessly in Dashboard.

Google Gadgets are available as a feature of Google Desktop. To get started with gadgets, head over to our Mac site and be sure to try out some of our other great Mac software! And if you want to create your own gadgets that run on Mac OS X and Windows, visit the Google Desktop Gadget API homepage to get started. We've added some new information to help you make sure that your new gadget runs fine on both platforms.

We're always working to improve our software, so if you've got any suggestions, drop them off in the Google Mac forum.

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.