How to pass vim buffer contents through shell command and capture the output to a split window

I would put something like this in my ~/.vimrc or a file with the .vim extension in ~/.vim/plugin/:

command! FW call FilterToNewWindow('myscript')

function! FilterToNewWindow(script)
    let TempFile = tempname()
    let SaveModified = &modified
    exe 'w ' . TempFile
    let &modified = SaveModified
    exe 'split ' . TempFile
    exe '%! ' . a:script
endfunction

Then you can just do ":FW".

It might be a good idea to change the command definition to require a filter script name argument to pass to the function instead of "hard coding" it.