Introducing Carmen!

2008.05.20 in code

I'm happy to finally be to a point in development where I can't really see myself giving up on this project, so I think that means it's time to write a post about it! This is going to be very ... freeform ... and varied in technical detail throughout. More of a ... launchpad for ideas and examples than a ... press release!

Carmen is a Mac OS X application which watches for changes in your environment, and allows you to assign actions to particular environments. Taken most simply, this allows you to perform numerous different tasks when you, say, move your computer from your home to your office. However, the power of Carmen is made clear when you want to act upon more subtle changes — say, the presence of a device, of a power adapter, etc.

I was inspired to design and write Carmen after spending a few months with MarcoPolo. While MarcoPolo is wonderful, it's GUI leaves something to be desired, and it's missing a fundamental level of power that I couldn't really see implementing within the existing codebase. I'm borrowing a LOT of code from MarcoPolo, mostly from their many excellent actions and evidence sources. MarcoPolo is GPL'd, and, unlike the other handful of less-powerful but more-'pretty' alternatives, so is Carmen!

I've got lots of sketches and notes and things that I think I'm going to scan and post at some point, because I really don't have a mockup that I feel willing to post anywhere at all at this point. I (surprisingly, for a project like this!) need a lot of art, and I'm either going to have to buckle down and do it myself, or convince someone else to help me (we'll see!)... but that's really a blocker on having a good mockup to show off!

Time for extremely contrived examples within a list of features:

Environments are hierarchical — you can, for example, have a 'Home' environment, which has sub-environments 'Studio' and 'Kitchen'. Say, in the studio, you have a Bluetooth tablet, and you want your volume automatically muted so as not to disturb your creative juices. However, you take the same tablet to work, where you're continually on conference calls, and need to keep your volume unmuted. A wireless network at home indicates that you're in the 'Home' environment, and, combined with the connected tablet, Carmen realizes that it's OK to mute your volume. If you're connected to the VPN at work, it instead places you in the 'Work' environment, and doesn't evaluate the actions for the 'Studio' context.

Cascading Actions — I haven't thought about this much, but there's fragments written about it in my notes. This would involve the ability to set an action on, say, the 'Home' environment, and have it execute even if you're found to be in the 'Home/Studio' environment. This is not how hierarchical contexts work in MarcoPolo, but seems like a far more useful model to me!

Fuzzy Logic — when multiple rules are provided for an environment, the confidence that a particular rule gives to the whole is taken into account, giving extreme flexibility to the rule system. For example, if you have a dock for your phone on your desk at home, there's a good chance you're at your desk when your phone is attached to your computer, and you can add this as a rule with, say, 75% probability. However, if you're at work and need to sync your bookmarks, the fact that you're connected to the internal VPN can give, say, a 100% probability that you're at work, meaning that you won't get switched to your home context when you plug your phone in! Probabilities will be expressed in words, instead of percentages (unlike MarcoPolo's somewhat confusing and random slider), but — you get the picture!

Autolocate — this feature appears to be unique to Carmen (also, it desperately needs a better name). Based on some completely random and wacky formula that I made up by playing around with stuff in Mathematica after having not slept for well over 24 hours (and will write about at some future point in time) it allows Carmen to collect data on the strengths of wireless networks at a particular location, and then later compare the current information to saved states, and determine, with reasonable accuracy, one's location. What's really cool about this is that — in preliminary tests — I was able to walk a few dozen feet down the hall, make a new 'autolocate' location, and the demo code consistently and repeatedly distinguished between them, even though, the whole time, I stayed connected to a single network (the normal, MarcoPolo way of differentiating between network contexts). Now, this was in a college dorm, with lots of networks (something like 9) to work with. When you're talking about a single network, this really isn't feasible, and you'll have to rely on other sources (like the normal, MarcoPolo 'what network am I connected to' one)...

Plugins — Every action and rule is actually a full-blown plugin, allowing third parties to create plugins that enable Carmen actions on their software. The plugin system also allows for the development of a community around Carmen, updating actions and rules without the need for a new release of the entire package! An internet-based plugin update system similar to the one found in Quicksilver will be implemented in order to keep everyone's systems up to date, and to allow simple acquisition of new plugins as they are created. (of course, plugins allowed into this system will be thoroughly reviewed by myself, and will need to be GPL'd as well). MarcoPolo currently ships with rule plugins for: Audio output device, Bluetooth devices, Bonjour services, Firewire and USB devices, Light level, IP address, Displays, connected network, running applications, time of day, and power source. Since I'm borrowing their code, I expect to support all of these in the first version of Carmen, plus the Autolocate plugin. Eventually I hope to expand this list to many more! Actions in MarcoPolo include: setting default printer, changing desktop background, setting Adium/iChat status, setting default outgoing mail server, mounting network drives, changing system audio volume, opening or closing an application, changing the timeout on the screensaver, running a shell script, toggling Bluetooth, WiFi, and any VPNs. Again, I expect to support all of these (and attempt to repair the ones that are currently somewhat broken, like setting the Adium status!) in the first shipping version of Carmen!

Guile-backed — (Power User Alert) This is where the crazy power of Carmen comes in! The probability of being in a particular location is actually the evaluated result of a Scheme s-expression. Something that looks like, say:

		(rule (ambient-light-range 0.6 1.0) 0.7)
		(rule (usb-device-connected "Apple iPhone") 0.9)
		(rule (not (usb-device-connected "RMS")) 1.0)
You have the complete power to edit this however you'd like, if you so wish. Adding any kind of complex logic — or anything else supported by the GNU Guile Scheme interpreter — is quite possible. More complex changes won't show up in the Carmen UI (we wouldn't need Scheme behind the scenes if we could specify everything everyone's ever going to want in the GUI!), but a special 'advanced user' mode will toggle on, constantly providing a color-coded view of the Scheme source for each context, easily editable to match whatever your desires may be. I'm not even going to try to come up with an example for this section — there's so many possibilities!

Small Things — Sparkle automatic updater support, Growl support, icons for contexts, certainly more I'm forgetting at the moment!