Thursday, August 11, 2022

#1 2009-11-24 08:30:30 am

rlesperance
Member
From:: Québec, Canada
Registered: 2002-11-20
Posts: 429

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 ?

Offline

 

#2 2009-11-24 10:33:25 am

Richard
Member
From:: Herefordshire, UK
Registered: 2009-09-09
Posts: 529
Website

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

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

Offline

 

#3 2009-12-01 08:35:04 pm

rlesperance
Member
From:: Québec, Canada
Registered: 2002-11-20
Posts: 429

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

Hi Richard, 

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

Applescript:

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

Offline

 

#4 2022-08-02 06:57:06 am

KniazidisR
Member
From:: Greece
Registered: 2019-03-03
Posts: 2443

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

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:

Applescript:


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:

Applescript:


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

Last edited by KniazidisR (2022-08-02 07:49:24 am)


Model: MacBook Pro
OS X: Catalina 10.15.7
Web Browser: Safari 14.1
Ram: 4 GB

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)