2013-07-31 48 views

回答

9

這是一個可能適合你的命令。這會告訴你自從鼠標移動或按下按鍵以來已經有多長時間了。

set idleTime to do shell script "ioreg -c IOHIDSystem | awk '/HIDIdleTime/ {print $NF/1000000000; exit}'" 

所以,你可能會認爲,如果按任何鍵或鼠標移到了那麼用戶不使用電腦一段時間。通過一些聰明的idleTime跟蹤,您可以知道用戶何時離開計算機以及何時返回。像這樣的東西。

將其另存爲一個applescript應用程序,然後選中「在運行處理程序後保持打開狀態」複選框。您可以隨時通過右鍵單擊停靠欄圖標並選擇退出來退出它。

global timeBeforeComputerIsNotInUse, computerIsInUse, previousIdleTime 

on run 
    set timeBeforeComputerIsNotInUse to 300 -- 5 minutes 
    set computerIsInUse to true 
    set previousIdleTime to 0 
end run 

on idle 
    set idleTime to (do shell script "ioreg -c IOHIDSystem | awk '/HIDIdleTime/ {print $NF/1000000000; exit}'") as number 

    if not computerIsInUse then 
     if idleTime is less than previousIdleTime then 
      set computerIsInUse to true 
      say "User is using the computer again." 
     end if 
    else if idleTime is greater than or equal to timeBeforeComputerIsNotInUse then 
     set computerIsInUse to false 
     say "User has left the computer." 
    end if 

    set previousIdleTime to idleTime 
    return 1 
end idle 
1

看一看iAway,一個小應用程序,它允許你運行Apple腳本,當你從你的Mac和返回一步之遙。我使用它來設置我的Messenger應用程序的在線狀態,並在離開時以及返回時設置我的在線狀態時啓動我的屏幕保護程序。該應用程序附帶其他很酷的功能,以實際檢測您是否在身體上遠離計算機視覺。