Skip to content

Instantly share code, notes, and snippets.

@marioaquino
Created October 2, 2010 21:07
Show Gist options
  • Save marioaquino/607998 to your computer and use it in GitHub Desktop.
Save marioaquino/607998 to your computer and use it in GitHub Desktop.
def js_command(command)
"-e 'do JavaScript \"#{command}\" in first document'"
end
def reload
js_command("window.location.reload();")
end
def scroll
js_command("window.scrollTo(0, document.body.scrollHeight);")
end
def safari_cmd(*cmds)
"osascript -e 'tell app \"Safari\"' #{cmds.join(' ')} -e 'end tell'"
end
def reload_and_scroll
safari_cmd reload, scroll
end
def scroll_to_bottom
safari_cmd scroll
end
def run_it(command = scroll_to_bottom)
system("ps -xc|grep -sq Safari && #{command}")
end
system("open /Applications/Safari.app KoansRunner.html")
run_it
watch( 'koans/.*\.js' ) { run_it(reload_and_scroll) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment