Install the following [script from Github](https://raw.github.com/euskadi31/Photoshop-CSS-Sprite/):
```css
wget https://raw.github.com/euskadi31/Photoshop-CSS-Sprite/master/PSprite.jsx
mv PSprite.jsx /Applications/Adobe\ Photoshop\ */Presets/Scripts
```
Then:
\* create some layers in your PSD file
\* name your layers
\* select File->Scripts->PScript
\* open /.css in an editor