I have been spending most of my time over on the Applescript OBJ-C list but am trying meanwhile to keep my ASS app alive on Snow Leopard.
I have a table in a split view that has a key down event handler
on keyboard down theObject event theEvent
if name of theObject = "backups" then
set theKeyPressed to (key code of theEvent)
if theKeyPressed = 51 then
--process rows to remove
end keyboard down
This previously worked fine in leopard and earlier. Now I get the error:
2009-10-26 21:57:44.448 backuplist+[1999:903] *** Assertion failure in -[NSEvent keyCode], /SourceCache/AppKit/AppKit-1038.11/AppKit.subproj/NSEvent.m:1901
2009-10-26 21:57:44.448 backuplist+[1999:903] An exception was thrown during execution of an NSScriptCommand…
2009-10-26 21:57:44.448 backuplist+[1999:903] Invalid message sent to event “NSEvent: type=Timer loc=(700,653) time=0.0 flags=0x100 win=0x0 winNum=0 ctxt=0xe1d3 subtype=0 data1=0 data2=0”
it logs theEvent as event 1 but there is no way to get key code or anything else out of it. I saw an earlier post about this and double clicked handler and wonder if anyone has since found a way to get a key code in SNow Leopard.
Thanks, Rob D
Not that it’s likely to be of much help, but that log entry suggests you’re not actually getting a keyboard event. The only events that have subtype, data1 and data2 methods are NSAppKitDefined, NSSystemDefined, and NSApplicationDefined, according to the docs.
I suppose it’s always possible that you’re trapping extra events, and the events you want are still in the queue – you could test this out by putting the attempt to get the key code in a try/end try, or if that doesn’t work, check the type of the event.
I usually come here for tips, so I hope this is useful to others.
I had the same issue show up in an app I was updating for Snow Leopard. And had the "Assertion failure . . . . " errors too, and this fix stopped it. The “key code of theEvent” was failing no matter how I tried to use it.
The fix for this is to enable the Delete menu item in the Edit menu in the main nib (or add it if not present) and assign the Delete key (Backspace on Macs) to it. In Interface Builder’s Attributes Inspector, assign the Delete key to it by simply clicking in the Key Equiv. box and pressing the Delete key.
In the code example below when the Edit menu Delete item is selected or the Delete key pressed, the code is executed. In my app the delete key is used only to delete list items, hence the name assigned to it in Interface Builder is “deleteListItem”.
--// menu item choices //--
on choose menu item theObject
set menuName to name of theObject
if menuName is "deleteListItem" then
If you don’t want to use the Edit menu Delete item another way is to use “on clicked” in the interface and a modifier key such as Command, Option or Control key. In the code example below “event 1” passes the key event to the handler as follows.
on clicked objectClicked
set objName to name of objectClicked
if option key down of event 1 then set optionKey to true
--// list functions //--
if objName is "sheetsTable" and optionKey then
Many thanks to all that contribute here, this is my 4th year with a commercial app in distribution.