Page refresher

Hi guys,
I have a script that is supposed to keep a Safari web page alive while I am doing other things, by periodically refreshing with “command r”. the only trouble is that the page refreshes no matter what, even if I am actively working in it (obviously disruptive). Also, if I am using a different program for a moment, the refresh operation interrupts what I am doing and brings Safari frontmost, disrupting my other work. Is there a way to make the refresh happen only during inactivity, and silently in the background?

My script
on idle –
tell application “Safari”
end tell
tell application “System Events”
tell process “Safari”
keystroke “r” using {command down}
end tell
end tell
return 90 – safari will refresh every 90 seconds
end idle

Any thoughts appreciated


an easy page refresher is

tell application "Safari"
	tell document 1 to set URL to (get URL)
end tell