Can't make "28.4 0.0" into type integer or

Hi,

Mostly on my new iMac running Snow Leopard, with an idle handler I get these 2 error:

“Can’t make “28.4
0.0” into type integer”

and

“Can’t make “0.0” into type number”

I got those same message on my Tiger machine but less frequently.

Where can I find a clue to these error messages ?

Could you paste this handler and if needed a typical input?

Hi Richard,

It took a while, but this case is now resolve. The message resulted from this script line:

set idleTime to (do shell script "ioreg -c IOHIDSystem | perl -ane 'if (/Idle/) {$idle=(pop @F)/1000000000; print $idle,\"\";last}'") as integer

By replacing the “as integer” by the “round” function that message stopped. I don’t know why one statement works while the other doesn’t, but I can now go forward with the rest of the script.

Thanks for helping.

Robert

Great example of the problems a user can create if they ignore the current decimal separator setting on numeric strings.

As a result, the users above cannot coerce a string into a real or integer. The reason is that ioreg returns a string with a period (“.”), and in the computer settings for the decimal separator the user has a comma (“,”) or something else.

Therefore, in order to coerce the result of ioreg into a real (or an integer), you have to work a little:


on getIdleTimeAsReal()
	-- get IDLE time in its text form (as is)
	set idleTime to do shell script "ioreg -c IOHIDSystem | perl -ane 'if (/Idle/) {$idle=(pop @F)/1000000000; print $idle,\"\";last}'"
	-- determine automatically current setting for decimal separator
	set decimalSeparator to middle character of (0.0 as text)
	-- replace decimal separator with appropriate one
	if decimalSeparator is not "." then
		set ATID to AppleScript's text item delimiters
		set AppleScript's text item delimiters to "."
		set idleTime to text items of idleTime
		set AppleScript's text item delimiters to decimalSeparator
		set idleTime to idleTime as text
		set AppleScript's text item delimiters to ATID
	end if
	-- now you can coerce the text to the number
	set idleTime to idleTime as real
end getIdleTimeAsReal

my getIdleTimeAsReal()

.
.
NOTE:
Getting the idle time as an integer is easy:


set idleTimeAsInteger to (do shell script "/usr/sbin/ioreg -c IOHIDSystem | /usr/bin/awk '/HIDIdleTime/ {print int($NF/1000000000); exit}'") as integer