Created
May 31, 2012 14:28
-
-
Save tonycosentini/2843738 to your computer and use it in GitHub Desktop.
Safari Reload Vim Plugin
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
autocmd BufWriteCmd *.html,*.css,*.gtpl :call Refresh_safari() | |
function! Refresh_safari() | |
if &modified | |
write | |
execute "silent ! osascript ~/.vim/applescript/reload_safari.applescript" | |
endif | |
endfunction |
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
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