Thursday, April 06, 2006

The little hidden built-in calculator

I just learned this little trick a few days ago, but I guess it's not really all that new. Almost all Cocoa text areas can perform calculations right inline. You just have to type a calculation, highlight it, hit Command-Shift-8, then the calculation will be evaluated and replaced by the answer. Pretty cool. For example, if I type 3^(2*pi), then highlight it and hit Command-Shift-8, it will be replaced with 995.041644892855.

You'll probably notice that the Sript Editor application opens when you do this. That's because the feature is implemented as a Service provided by the Script Editor. What's really happening is that the highlighted text is being executed as AppleScript. So, as I sit here typing into this text area in Safari, I could highlight and execute

tell application "Safari" to display dialog "Hello"
(don't ask me why I'd want to run that AppleScript from right here).

I'm sure there's much cooler stuff you can do wit this trick, but regardless it's pretty cool.

1 comment:

Anonymous said...

Hey, that's a nice trick. Thanks :-)