How do I add a  class based on the visibility of a block?
You have to do it via the template_preprocess_html function.

Add this to your theme's template.php file:

function MYTHEME_preprocess_html(&amp;$variables) {
  // dpm($variables);
  $node = menu_get_object();
  if (isset($node) &amp;&amp; isset($variables['page']['sidebar_first']['system_navigation'])) {
     $variables['classes_array'][] = 'system-navigation';
  }
}


In the above code I am looking for the system navigation block in the sidebar first region and if it is there I am adding system-navigation class to the classes array. I am also checking if I am on a node page via the call to menu_get_object()

You will have to adapt the code to your use case. 

Install the devel module, then uncomment the dpm statement. Then look under the page variable at other variables without a # in front of them.