Don Marti
Sun 17 Apr 2005 08:33:52 PM PDT
eval button
(updated 4 Mar 2005: updated clipboard version to "copy" instead of "cut")
Jef Raskin wrote
All that is really needed on computers is a "Calculate" button or omnipresent menu command that allows you to take an arithmetic expression, like 248.93 / 375, select it, and do the calculation whether in the word processor, communications package, drawing or presentation application or just at the desktop level.
Fortunately, there's a blue "Access IBM" button on this keyboard that doesn't do anything. So, I configured tpb to make "Access IBM" do this:
perl -e 'print eval `xsel -o`' | \ xsel -i && xte 'key Delete' 'mouseclick 2'
(That is, get the contents of the X primary selection, run it through a Perl "eval", put the result back into the X primary selection, then fake a delete and paste.)
Here's a version that uses the X clipboard selection instead.
xte 'keydown Control_L' 'key c' 'keyup Control_L' && \ perl -e 'print eval `xsel -b -o`' | xsel -b -i && \ xte 'keydown Control_L' 'key v' 'keyup Control_L'
This one seems to work better in gedit.
So, say you're filling out a web form and you want to buy sqrt(9) pcHDTV cards. All you have to do is fill in the expression, select it, and press "Access IBM". Yippee! One, two, three units of soon-to-be-illegal, better-buy-them-now freedom-compatible hardware.
If you want to do this, besides tpb, you'll need xsel and xte, which is part of xautomation. If you don't have an unused button, you could also set up a binding in your window manager or build a big red outboard USB "eval" button or something.