   Usage:
     % theta --capture
     % theta --capture out.jpg
-    % DEBUG=* theta capture
+    % theta --list
+    % theta --id [object_id] --save out.jpg
+    % DEBUG=* theta --capture
   """
   console.log parser.toString()
   process.exit 0
+
+savePicture = (object_id, filename) ->
+  theta.getPicture object_id, (err, picture) ->
+    if err
+      console.error err
+      return process.exit 1
+    fs.writeFile filename, picture, (err) ->
+      console.log "picture (ID:#{object_id}) saved => #{filename}"
+      theta.disconnect()
 
 parser.on 'capture', (opt, filename) ->
   theta.connect()

        return theta.disconnect()

  theta.once 'objectAdded', (object_id) ->
    theta.getPicture object_id, (err, picture) ->
      if err
        console.error err
        return process.exit 1
      fs.writeFile filename, picture, (err) ->
        console.log "picture saved => #{filename}"
        theta.disconnect()

parser.parse process.argv

parser = new optparse.OptionParser [
  ['-h', '--help', 'show help']
  ['--capture [FILENAME]', 'take a picture']
  ['--list', 'list pictures']
  ['--id [Object ID]', 'specify picture by ID']
  ['--save [FILENAME]', 'save picture']
]

parser.on 'help', ->
