How to add variables to Drupal.settings using form#attached?
Documentation is available:

Form API

$settings = array('id' =&gt; 'mymodule-element-1');

$form['#attached']['js'][] = array(
  'data' =&gt; array('mymodule' =&gt; $settings),
  'type' =&gt; 'setting',
);


Managing JavaScript in Drupal 7

$element['#attached']['js'][] = array(
  'type' =&gt; 'setting',
  'data' =&gt; array('myModule' =&gt; array('key' =&gt; 'value')),
);


Both are roughly the same as what OP (@drupality) said worked for him in a comment on Jun 14 2013.

The code in the original question that the OP said he tried but fails seems roughly the same as the working code, so I can't see what the original error was.