Created
May 23, 2012 13:53
-
-
Save biojazzard/2775348 to your computer and use it in GitHub Desktop.
Applescript Idle Timed Actions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Remember to Save as... Application | |
-- I don´t remember where I Saw it. | |
```AppleScript | |
global quit_after, check_every, app_name | |
set quit_after to 30 | |
set check_every to 5 | |
set app_name to "djay" | |
display dialog "Check is performed every " & check_every & " seconds. Things will be quit after " & quit_after & " seconds of system inactivity." | |
on reopen | |
display dialog "Check is performed every " & check_every & " seconds. Things will be quit after " & quit_after & " seconds of system inactivity." | |
end reopen | |
on idle | |
set idletime to do shell script "echo $((`ioreg -c IOHIDSystem | sed -e '/HIDIdleTime/ !{ d' -e 't' -e '}' -e 's/.* = //g' -e 'q'` / 1000000000))" | |
if (idletime as integer) > quit_after then | |
tell application "System Events" | |
if ((name of processes) contains "djay") then | |
--tell application "djay" to quit | |
--display dialog "ok djay loaded" | |
tell application "djay" | |
activate | |
delay 0.1 | |
set crossfader to position -1.0 | |
end tell | |
else | |
display dialog "djay NOT LOADED!!!" | |
end if | |
end tell | |
end if | |
return check_every | |
end idle | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment