• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Idle Time
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Idle Time


  • Subject: Re: Idle Time
  • From: Graff <email@hidden>
  • Date: Sun, 16 May 2004 01:54:56 -0400

From what I understand that's pretty close to the optimal solution. The only thing is that the format of the idle time has changed with Mac OS X 10.3. Prior to 10.3 the value returned is in hexadecimal, with 10.3 it is now a decimal number. So you need to detect the version of Mac OS X the user is running and treat the data accordingly:
----
display dialog "The user was idle for " & IdleTime() & " seconds"

delay 3
display dialog "The user was idle for " & IdleTime() & " seconds"

on IdleTime()
set ioregResult to do shell script "ioreg -c IOHIDSystem | awk '/Idle/ {x = $5} END {print x}'"

-- Check the version of the OS
set systemVersion to my NumToHex(system attribute "sysv")

if the systemVersion is greater than or equal to "1000" then
-- we are using Mac OS X
if the systemVersion is less than "1030" then
-- we are not using Panther
set secondsIdle to hex2Dec(text from character 2 to -2 of ioregResult) / 1.0E+9
else
-- we are using Panther
set secondsIdle to (ioregResult as number) / 1.0E+9
end if
end if

return secondsIdle
end IdleTime

-- this function adapted from
-- <http://www.apple.com/applescript/guidebook/sbrt/pgs/sbrt06.htm>
on NumToHex(hexData)
set hexString to {}
repeat 4 times
set hexString to ((hexData mod 16) as string) & hexString
set hexData to hexData div 16
end repeat
return (hexString as string)
end NumToHex

on hex2Dec(hexNum)
set decNum to 0
set hexDigits to "123456789ABCDEF"
set Nbdigits to (length of hexNum) - 1
repeat with i from 0 to Nbdigits
set lastOne to character (Nbdigits + 1 - i) of hexNum
set decNum to decNum + (offset of lastOne in hexDigits) * (16 ^ i)
end repeat
return decNum
end hex2Dec

- Ken

On May 15, 2004, at 2:32 PM, Jeffrey Berman wrote:

I have some script actions I want to occur only if the computer has been
idle for some period of time. My machine is running OS X 10.2.8 and I have
been using 'ioreg' in the syntax below to obtain an idle time. Does anyone
know if there is a simpler way to access the time during which there has
been no keyboard or mouse actions?

-Jeffrey Berman


----- Attachment follows -----

do shell script "ioreg -c IOHIDSystem | awk '/Idle/ {x = $5} END {print x}'"
return hex2Dec(text from character 2 to -2 of result) / 1.0E+9
-- seconds computer has been idle

on hex2Dec(hexNum)
set decNum to 0
set hexDigits to "123456789ABCDEF"
set Nbdigits to (length of hexNum) - 1
repeat with i from 0 to Nbdigits
set lastOne to character (Nbdigits + 1 - i) of hexNum
set decNum to decNum + (offset of lastOne in hexDigits) * (16 ^ i)
end repeat
return decNum
end hex2Dec

----- End of attachment -----
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.


References: 
 >Idle Time (From: Jeffrey Berman <email@hidden>)

  • Prev by Date: Re: Flattening a list
  • Next by Date: Darmouth
  • Previous by thread: Idle Time
  • Next by thread: (no subject)
  • Index(es):
    • Date
    • Thread