views:

41

answers:

1

I'm trying to make an extension that closes all tabs but the active tab for the current window in Safari. I have gotten this far as to close all tabs but index 1. But I need to insert the activetab index and exclude that from the closings. If I get the answer I'd put it in the extension and publish it.

<!DOCTYPE HTML>
<script>
safari.application.addEventListener("command", performCommand, false);
safari.application.addEventListener("validate", validateCommand, false);
function performCommand(event)
{   
if (event.command !== "closer")
        return;
    var tabss = safari.application.activeBrowserWindow.tabs;

        for (j=1; j<tabss.length; j++) {

                event.target.browserWindow.activeTab.close();

            }
 }
</script>
A: 

What you need to do is iterate through all the tabs in the window closing those which aren't the active tab, for example:

Pseudo-code: Not a copy and paste example...

for (var i = 0; i < tabs.length; i++)
{
    if (tab[i] !=== activeTab)
    {
        tab[i].close();
    }
}
unknowndomain