<!DOCTYPE html>
<html>

  <head>
  
    <script type="text/javascript">
      
      const bars = safari.extension.bars;
      
      function performCommand(event)
      {
        if (event.command == 'searchmarks.button.toggle-bar')
        {
          toggleSearchmarksBar();
        }
      }
      
      function validateCommand(event)
      {
      }
    
      function toggleSearchmarksBar()
      {
        for (var i = 0; i < bars.length; ++i)
        {
          var bar = bars[i];
          if (bar.browserWindow === safari.application.activeBrowserWindow && bar.identifier === "searchmarks.bar")
          {
            if (bar.visible)
              bar.hide();
            else
              bar.show();
          }
        }
      }
      
      safari.application.addEventListener("command", performCommand, false);
      safari.application.addEventListener("validate", validateCommand, false);
    
    </script>
  
  </head>

  <body>
  </body>

</html>
<!DOCTYPE html>
<html>

  <head>
  
    <script type="text/javascript">
      
      const bars = safari.extension.bars;
      
      function performCommand(event)
      {
        if (event.command == 'searchmarks.button.toggle-bar')
        {
          toggleSearchmarksBar();
        }
      }
      
      function validateCommand(event)
      {
      }
    
      function toggleSearchmarksBar()
      {
        var found = false;
        
        for (var i = 0; i < bars.length; ++i)
        {
          var bar = bars[i];
          
          if (bar.browserWindow === safari.application.activeBrowserWindow && bar.identifier === "searchmarks.bar")
          {
            if (bar.visible)
              bar.hide();
            else
              bar.show();
              
            found = true;
          }
        }
        
        if (!found)
        {
          alert("Error: Searchmarks bar not found. I don't know why this happens, but I am trying to track it down.");
          throw "Searchmarks bar not found";
        }
      }
      
      safari.application.addEventListener("command", performCommand, false);
      safari.application.addEventListener("validate", validateCommand, false);
    
    </script>
  
  </head>

  <body>
  </body>

</html>
Add error message when toggle button doesn't work for some reason
Add error message when toggle button doesn't work for some reason