How are LEGO bricks packaged?
This is a comprehensive walk-through:

http://gizmodo.com/exclusive-look-inside-the-lego-factory-5022769

The last video shows how parts are retrieved from the shelves, decorated, packaged in plastic bags and put into set boxes. It is probably exactly how you imagined the process :)