This one was quite a challenge!! I put together an AutoHotKey script which automatically transfers the items in your inventory to a chest and vice-versa by simulating mouse clicks.
Watch a video of it in action (YouTube)
As it requires AutoHotKey I think it's only good for Windows users right now, but if someone wants to port it to another platform, feel free (a lot of the gnarly window/layout calculations could be reused). It could probably be extended to do some other tricks - let me know if you come up with anything!
== How to get started ==
Install AutoHotKey, download the mineswap.ahk script, then double click the script to run it.
When you want to swap contents of your inventory with a chest, ensure you've already opened the chest, then type one of the following shortcuts:
Swap inventory with contents of single chest: ]ss
Swap inventory with top 3 rows of large chest: ]sc1
Swap inventory with bottom 3 rows of large chest: ]sc2
If you want to change the shortcuts, it's pretty easy, just open the script in something like Notepad, save it, then double click the script again to reload it.
By default there's a delay of 50ms between each mouse click. If it's too fast and makes mistakes, try increasing this value.
== The technical stuff ==
It should support any screen resolution including windowed or fullscreen mode. The script calculates the pixel positions of the chest/inventory slots based on the current window dimensions and resolution. As the resolution increases, the pixels in the chest display get doubled/tripled and so on by Minecraft to fit nicely onto the screen so the script has to take this into account. The chest display is always centered on the screen but the layout also varies depending on whether it's a large or single chest (ouch). After some funky calculations it loops through all the cells and clicks alternately between the inventory and chest to swap the items. I've tried to structure the script to make it easy to extend, so feel free to tweak it for your own requirements. Released under modified BSD licence.