Dashboard Calculator Fix for Lion

Problem

Among many great changes introduced in Mac OS X Lion there is tiny but really annoying one. In Dashboard Calculator widget the "clear" button on the numeric keypad no longer works. Also the font face of the display was changed from cool looking LCD to boring Helvetica. We personally consider this as a bug and hope Apple will fix it in the future updates.

Solution

Download already patched Widget or follow the instruction.

First, open the widgets directory, which is located at:

/Library/Widgets

There you will see all the system widgets. Find Calculator.wdgt and back it up somewhere. Then right click on the file and choose "Show Package Contents".

You will need any text editor to make changes. For example TextEdit.app will do the job. Note, that authentication may be required to gain permission to save the changes.

Open Calculator.js file with your editor and locate a block of code at line 127:

case 63289:
case 27:
	key = "c";
	break;

Replace number 63289 with 61705. After the edit your code should look like this:

case 61705:
case 27:
	key = "c";
	break;

To set the font face of the display back to LCD open Calculator.css file and locate a block of code at line 16:

font: 20.25px HelveticaNeue, sans-serif;

Modify it to match the following code:

font: 20.25px "DBLCDTempBlack", HelveticaNeue, sans-serif;

To view the result you need to add a new Calculator widget to your Dashboard.

Explanation

The translateKey() function in Calculator.js was changed a bit in Lion. Following lines of code were added at the beginning of the function:

var code = e.charCode ? e.charCode:e.keyCode;

// convert from unicode if necessary
code = (code > 1584 ) ? code - 1584:code;

So when we press "clear" key which has a code of 63289, 1584 is subtracted from it. The following switch block has a case only for the original "clear" key code value, but not for the modified. We don't know yet why exactly 1584 is subtracted. However, we suppose that "convert from unicode if necessary" code should be executed only if e.charCode evaluates to true:

var code;
if(e.charCode)
{
	code = e.charCode;
	
	// convert from unicode if necessary
	code = (code > 1584 ) ? code - 1584:code;
}
else
{
	code = e.keyCode;
}

The LCD font face was removed just from the stylesheet selector, not from the widget. The .ttf file is still present in the package.