NSDate not working with the debugger on

The script gets an “Error -1763 occurred. Couldn’t write data because C and Objective-C pointers cannot be saved in script” while in the GetKeyFlags handler and then it highlights the “return ReturnObj” at end of “GetKeyFlags” handler and displays the error shown below.
Error%20dialog

If I turn debugging off the script runs with no problems. Is ASObj-C supposed to work with the debugger on? I’ve never tried that before. I uploaded the script to this post and the script listing is at the end of this post.

Here is the script listing.

use framework "Foundation"
use framework "AppKit"

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions


property TheInterval : 1

on GetKeyFlags(IntegerNumber)
	script ReturnObj
		property Successful : false
		property BinaryNumber : {}
		property NumberOfBits : -1
	end script
	
	try
		set TheBinaryNumber to {}
		repeat while IntegerNumber ≥ 1
			if (IntegerNumber mod 2) = 0 then
				set TheBinaryNumber to {0} & TheBinaryNumber
			else
				set TheBinaryNumber to {1} & TheBinaryNumber
			end if
			set IntegerNumber to IntegerNumber div 2
		end repeat
		set (BinaryNumber of ReturnObj) to TheBinaryNumber as string
		set (NumberOfBits of ReturnObj) to count of TheBinaryNumber
		set (Successful of ReturnObj) to true
		return ReturnObj
	on error errMsg number errNum
		display dialog "Error " & (errNum as string) & " occured." & return & return & errMsg ¬
			buttons {"OK"} default button "OK" with title "Error"
		set (Successful of ReturnObj) to false
		return ReturnObj
	end try
end GetKeyFlags

delay 2

set StartTime to current application's NSDate's |date|()

set TheFlags to current application's NSEvent's modifierFlags() as integer

-- The "div 65536" stips off the lower 16 bits that do not carry any information about keys pressed.
set TheResult to GetKeyFlags(TheFlags div 65536)

if ((BinaryNumber of TheResult) = "1") then
	return "CapsLock key"
else if ((BinaryNumber of TheResult) = "10") then
	return "Shift key"
else if ((BinaryNumber of TheResult) = "100") then
	return "Control key"
else if ((BinaryNumber of TheResult) = "1000") then
	return "Option key"
else if ((BinaryNumber of TheResult) = "10000") then
	return "Command key"
else if ((BinaryNumber of TheResult) = "100000") then
	return "NumericPad"
else if ((BinaryNumber of TheResult) = "1000000") then
	return "Help key"
else if ((BinaryNumber of TheResult) = "10000000") then
	return "Function key"
end if

set EndTime to current application's NSDate's |date|()
set RunTime to EndTime's timeIntervalSinceDate:StartTime
return RunTime

key test 2.scptd.zip (12.0 KB)

I’m not sure why it’s not working, but I suspect the issue is not ASObjC per se, but rather the interaction between it and your use of a script object. if you use a record instead:

	set ReturnObj to {Successful:false, BinaryNumber:{}, NumberOfBits:-1}

the problem goes away.

BTW, you’re doing this modifier stuff the hard way. I’ll post a simpler way in the public areas, because it may be of more general interest.

@BillKopp, you might try your script in release 7A37. It should resolve the issue you’re seeing.