Add stylesheets and js to template files when shortcode is used

put wp_enqueue_script() in your shortcode handler.

add_shortcode('myshortcode', 'my_shortcode_handler');

function my_shortcode_handler($atts) {
  wp_enqueue_script('my-script', plugins_url('my-script.js', __FILE__), array('jquery'), '1.0', true);

  // actual shortcode handling here
  return "bacon flavored shortcode here";
}

this definitely loads the my-script.js file for me. it gets loaded in the footer though. i don’t think there is a way for it to load conditionally in the header as it won’t have gotten to the post content to know whether the shortcode is used or not.

check this:
http://scribu.net/wordpress/conditional-script-loading-revisited.html