Skip to content

Instantly share code, notes, and snippets.

@ivanski
Created December 6, 2023 01:32
Show Gist options
  • Save ivanski/ad4825649b544a11186b22c1987c12f8 to your computer and use it in GitHub Desktop.
Save ivanski/ad4825649b544a11186b22c1987c12f8 to your computer and use it in GitHub Desktop.
Split/Copy Safari Tabs
set destWindowIsNew to true
set optionList to {"Copy Tabs", "Move Tabs"}
set tabsAction to choose from list optionList with prompt "What to do with tabs:" default items {"Move Tabs"}
set closeTabs to tabsAction contains "Move Tabs"
tell application "Safari"
set sourceWindow to front window
set sourceTabs to tabs of sourceWindow
set startSourceTabIndex to index of current tab of sourceWindow
set sourceTabCount to count of sourceTabs
if destWindowIsNew then
make new document
set destWindow to front window
else
set destWindow to window 2
end if
repeat with i from startSourceTabIndex to sourceTabCount
set u to URL of item i of sourceTabs
if u is not missing value then
set destTab to make new tab at end of tabs of destWindow
set URL of destTab to u
end if
end repeat
if closeTabs then repeat with i from startSourceTabIndex to sourceTabCount
close item startSourceTabIndex of sourceTabs
end repeat
activate
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment