How to add javascript to theme_preprocess_user_login I have working code in my theme's template.php file that adds "autofocus" to my modal login form, but Firefox ignores ajax autofocus fields (only applies autofocus on pageload). So I'm trying to add some js to set focus when the modal login form is called. I currently add autofocus via:

function mytheme_preprocess_user_login(&amp;$variables) {
  $variables['form']['name']['#attributes']['autofocus'] = array('autofocus');
  $variables['rendered'] = drupal_render_children($variables['form']);
}


And I'm trying to add js to set focus as a fallback this way:

function mytheme_preprocess_user_login(&amp;$variables) {
  $variables['form']['name']['#attributes']['autofocus'] = array('autofocus');
  $variables['form']['#attached'][js][] = path_to_theme() . "/js/focus.js";
  $variables['rendered'] = drupal_render_children($variables['form']);
}


but this doesn't seem to add the js as expected. How can I add either inline or external javascript to my modal login form?
A preferred solution I would use for adding/editing forms would be to use a module hook.

function MODULE_form_user_login_alter(&amp;$form, &amp;$form_state, $form_id) {

  $form['#attached']['js'] = array(
    drupal_get_path('theme', 'THEME') . '/js/focus.js',
    '/* inline js here */' =&gt; array( 'type' =&gt; 'inline')
  );
}