Search code examples
macossafaritabsapplescript

Applescript to split Safari tabs into new window


I'm trying to write a script that splits the current + all next tabs into a new window — which would be super useful for organization.

It is perfectly possible to get the URLs of the current and all next tabs, make a new window and load all those URLs in new tabs, and then close the tabs in the original window – but that seems very cumbersome and slow.

So, is there any way to move a set of Safari tabs to a new window without actually reloading the URLs?


Solution

  • Not sure if this is the best/right way, but got this working:

    tell application "Safari"
        set original_window to front window
        set tab_index to index of current tab of original_window
        set tab_limit to index of last tab of original_window
    
        make new document
        move tabs tab_index thru tab_limit of original_window to front window
        close first tab of front window
    end tell