property idleTest : 1800 -- How long to be idle (in seconds) before unmounting property sleepTime : 60 -- How often to test Idle time script unmount_all tell application "Finder" -- get every non-local disk set all_disks to every disk whose local volume is false -- go through all found disks and unmount repeat with current_disk in all_disks try ignoring application responses eject current_disk end ignoring end try end repeat end tell end script on idle_time() -- this is the crucial line that I don't claim credit for set idleTime to (do shell script "ioreg -c IOHIDSystem | perl -ane 'if (/Idle/) {$idle=(pop @F)/1000000000; print $idle,\"\";last}'") return idleTime end idle_time script should_quit set idleComp to false set runFlag to true -- this repeat loop polls the idle time to determine -- whether the system has been idle for the number of seconds defined above. -- It will repeat indefinitely until the idle time is acheived -- whereupon the action is performed repeat while runFlag is true set idleTime to idle_time() of parent set old_delims to AppleScript's text item delimiters set AppleScript's text item delimiters to "." set idleTime to ((first text item of idleTime as string) as integer) set AppleScript's text item delimiters to old_delims set idleTest to (idleTest as integer) if idleComp is false then if idleTime is greater than idleTest then set idleComp to true try -- put your sleep actions in here tell unmount_all to run end try end if else if idleTime is less than idleTest then set idleComp to false end if end if delay sleepTime end repeat end script tell should_quit to run