MacOS – Detach active Chrome tab using AppleScript

applescriptgoogle-chromemacos

I want to open current active tab in Chrome to a new window.

The intention of this to split tabs side by side (for use with BetterSnapTool).

I am new with AppleScript and find reading this a bit difficult. Can't really discern from methods and properties.

Best Answer

This works for me using the latest version of Mac OS High Sierra.

tell application "Google Chrome"
    tell its window 1
        set theURL to URL of active tab
        close active tab
    end tell
    set the URL of active tab of (make new window) to theURL
end tell

If you would like to see the two windows now side-by-side, Try this...

tell application "Finder"
    set currentDesktopBounds to bounds of window of desktop
end tell

copy currentDesktopBounds to leftBounds
set l to item 3 of leftBounds
set l to l / 2 as integer
set item 3 of leftBounds to l

copy leftBounds to rightBounds
set r to item 3 of rightBounds as integer
set r to r + 1 as integer
set item 1 of rightBounds to r
set item 2 of rightBounds to 22
set item 3 of rightBounds to item 3 of currentDesktopBounds
set item 4 of rightBounds to item 4 of currentDesktopBounds

tell application "Google Chrome"
    tell its window 1
        set theURL to URL of active tab
        close active tab
    end tell
    set the URL of active tab of (make new window) to theURL
    delay 0.2
    tell its window 1
        set bounds to leftBounds
    end tell
    delay 0.2
    tell its window 2
        set bounds to rightBounds
    end tell
end tell