Try this code, this will call when any sidebar is called:--
add_action('get_sidebar', 'add_before_siderbar');
function add_before_siderbar($name)
{
//Here `$name` is name of side bar, it will blank if default sidebar is call.
if($name == 'your-sidebar')
{
add_action( 'wp_enqueue_scripts', 'add_scripts' );
}
}
function add_scripts()
{
wp_enqueue_script( 'your-script', 'YOUR-SCRIPT-PATH', array( 'jquery' ), 'version', false);
}