Skip to content

Instantly share code, notes, and snippets.

@tonycosentini
Created May 31, 2012 14:28
Show Gist options
  • Save tonycosentini/2843738 to your computer and use it in GitHub Desktop.
Save tonycosentini/2843738 to your computer and use it in GitHub Desktop.
Safari Reload Vim Plugin
autocmd BufWriteCmd *.html,*.css,*.gtpl :call Refresh_safari()
function! Refresh_safari()
if &modified
write
execute "silent ! osascript ~/.vim/applescript/reload_safari.applescript"
endif
endfunction
tell front window of application "Safari"
set hscroll to (do JavaScript "(document.all ? document.scrollLeft : window.pageXOffset);" in current tab)
set vscroll to (do JavaScript "(document.all ? document.scrollTop : window.pageYOffset);" in current tab)
set the URL of current tab to URL of current tab
set scrollCode to "window.scrollTo(" & hscroll & "," & vscroll & ");"
--repeat until (do JavaScript "document.readyState" in document 1) is "complete"
--end repeat
delay 0.5
-- This is a complete hack. I originally tried to use JavaScript to wait until the page loaded,
-- but I was unable to find a way to "block" execution in AppleScript.
do JavaScript scrollCode in current tab
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment