All portable Macs go into sleep mode, or "clamshell" mode, as soon as the lid is closed, unless they are connected to an external monitor or projector, mouse and keyboard. To disable sleep mode when the lid is closed, you must have Mac OS X v10.6 or later installed on your MacBook, MacBook Pro, MacBook Air or PowerBook. The Apple iBook cannot be brought out of sleep mode when the lid is closed.
Energy Saver is what puts your Mac into sleep mode after the keyboard or mouse has been inactive for a predetermined amount of time, ranging from 1 minute to 3 hours, or never. Adjust these settings by opening the Energy Saver panel in System Preferences. Times for the computer and display to go into sleep mode are adjusted separately, and depending on whether the computer is being powered by a battery or is using a power adapter. Select "Never" to disable sleep mode. You need an external mouse, keyboard and monitor for this to work when the lid is closed.
Using a USB Mouse and Keyboard
Plugging a USB mouse and keyboard into your Mac, as well as an external monitor or projector, allows you to close the lid while keeping the computer active. To do this, simply plug in the mouse, keyboard and external monitor, and close the lid -- your Mac immediately goes into sleep mode. Press a key on the keyboard or move the mouse to bring it out of sleep mode. Your Mac stays awake until the times specified in the Power Saver settings.
Using a Bluetooth Mouse and Keyboard
A Bluetooth mouse and keyboard can also keep your Mac active when the lid is closed, provided it has also been connected to an external monitor or projector. Pair the mouse and keyboard to your Mac first by turning the device off and on again while within a couple feet of your computer. Activate Bluetooth on your Mac by going to the Bluetooth panel found in System preferences.
Using Wireless Wake on Demand
For sharing files on your Mac using a wireless network, you can also wake your Mac from sleep mode whenever another computer tries to access those files. When the lid is closed, you can only do this if the Mac is connected to an external mouse, keyboard and monitor. Otherwise, the lid must be open. Set this feature on your Mac in the Advanced panel in the Airport panel, found in the Network section of System Preferences.