I’d like to run an application automatically after the computer has been idle for say, 5 minutes. Don’t know much about writing scripts.
Thanks
Model: iMac
AppleScript: 1.9.3
Browser: Safari 312.6
Operating System: Mac OS X (10.4.1)
I’d like to run an application automatically after the computer has been idle for say, 5 minutes. Don’t know much about writing scripts.
Thanks
Model: iMac
AppleScript: 1.9.3
Browser: Safari 312.6
Operating System: Mac OS X (10.4.1)
Hi,
try this, save the script as stay open application
property triggerTime : 5 * minutes
property appToLaunch : "myApp.app"
on idle
set idleTime to (do shell script "ioreg -c IOHIDSystem | perl -ane 'if (/Idle/) {$idle=(pop @F)/1000000000; print $idle,\"\";last}'") as integer
if idleTime > triggerTime then
launch application appToLaunch
end if
return 10
end idle
Thanks. I tried substituting my Applescript “quitter” for “myApp.app” and hit ‘Run’
Nothing happened. No errors, Nothing.
Any ideas?
Won’t the act of running the script itself result in an idle time of 0 every time?
Correction. “Can’t make .23427860 a integer” comes up. A different number each time
It doesn’t seem to from this test…
delay 5
set idleTime to (do shell script "ioreg -c IOHIDSystem | perl -ane 'if (/Idle/) {$idle=(pop @F)/1000000000; print $idle,\"\";last}'") as integer
display dialog idleTime
show us your script
I get the same error message with this scriptlet - Can’t make ####### into a integer. It does say ‘a integer’ btw.
Here is the script:
property triggerTime : 1 * minutes
property appToLaunch : “quitter”
on idle
set idleTime to (do shell script “ioreg -c IOHIDSystem | perl -ane ‘if (/Idle/) {$idle=(pop @F)/1000000000; print $idle,"";last}’”) as integer
if idleTime > triggerTime then
launch application appToLaunch
end if
return 10
end idle
It works if I use the TextEdit application, so the problem is with your application “quitter”. Show us quitter’s code.
property triggerTime : 1 * minutes
property appToLaunch : "TextEdit"
on idle
set idleTime to (do shell script "ioreg -c IOHIDSystem | perl -ane 'if (/Idle/) {$idle=(pop @F)/1000000000; print $idle,\"\";last}'") as integer
if idleTime > triggerTime then
launch application appToLaunch
end if
return 10
end idle
“Quitter” works perfectly as is:
set goodProcs to {“Finder”} – Names of apps you want left
–theProcs is each running program
–myProc is each program-compare to list of programs to keep running
tell application “System Events” to set theProcs to name of every process whose visible is true
repeat with myProc in theProcs
if myProc is not in goodProcs then tell application myProc to quit saving no
end repeat
quiter looks OK. I didn’t try it though because I don’t want to quit all my apps… but anyway here’s the question… does my above script work for you i.e. with TextEdit? It should work because it works for me.
If “Quitter” is just a compiled script, not an app, then use this
property triggerTime : 5 * minutes
property scriptToRun : "path:to:myscript.scpt"
on idle
set idleTime to (do shell script "ioreg -c IOHIDSystem | perl -ane 'if (/Idle/) {$idle=(pop @F)/1000000000; print $idle,\"\";last}'") as integer
if idleTime > triggerTime then
run script scriptToRun
end if
return 10
end idle
Thanks for trying. Same error message over and over after the interval.