In my opinion this is a bug.
-------------------------------------------------------------------------------------------
Appended is a script I originally wrote back in 2004 or 2005 and rewrote several years ago to use only vanilla AppleScript. (It used to rely on the Satimage.osax.)
I spent a lot of time trying to make it work properly and to make it as fast as possible.
------------------------------------------------------------------------------------------
# dCre: 2010/10/16 00:42
# dMod: 2016/07/19 08:21
# Appl: Safari
# Task: Display a list of tab names and also a count of both documents & tabs.
# : Select a tab name to bring it to the front.
# : Adjusted to deal properly with duplicate tab names on 2013-05-30.
# Libs: Only stock OSX components used.
# Osax: None
# Tags: @Applescript, @Safari, @Choose, @Display, @Tabs, @Windows
-------------------------------------------------------------------------------------------
try
set sep to "----------------------------------------------------------------------------------------------------"
tell application "Safari"
if (count of document) ≥ 1 then
set frontWindoc to document of front window
else
error "No pages are open in Safari"
end if
tell (every window where its document is not missing value)
set docCount to count
set currentTabIndex to index of current tab
set tabCount to count of tabs
set tabNames to name of tabs
end tell
if docCount < 10 then set docCount to "0" & docCount
set hdrText to "Window Count: " & docCount & return & " Tab Count: " & tabCount
# Add tab-index to tab names to deal with duplicate names.
set ndx to 0
repeat with i in tabNames
repeat with n from 1 to (length of i)
if n < 10 then
set _num to "0" & n
else
set _num to n
end if
tell (a reference to item n of i) to set its contents to its contents & " · [" & _num & "]"
end repeat
end repeat
# Mark Current Tabs of each document window with '[✓]'
# tabNames is a list of lists.
set ndx to 0
repeat with i in tabNames
set ndx to ndx + 1
tell (a reference to i's item (item ndx of currentTabIndex)) to set its contents to (its contents) & " ✓"
if ndx = 1 then
set currentTabName to result
end if
set end of i to sep
end repeat
tabNames
set beginning of item 1 of tabNames to sep
set AppleScript's text item delimiters to return
set tabNames to paragraphs of (tabNames as text)
tell me to set _tab to choose from list tabNames with title "•• Safari Tab Names ••" with prompt hdrText ¬
default items {currentTabName} with empty selection allowed
if _tab = false then return
set _tab to item 1 of _tab # De-listify.
set AppleScript's text item delimiters to " · "
set tabName to text item 1 of _tab
set AppleScript's text item delimiters to {"· ["}
set tabIndex to (text item 2 of _tab)
set AppleScript's text item delimiters to {"]"}
set tabIndex to (text item 1 of tabIndex) as integer
tell windows
set tabID to tabs whose name contains tabName and index is tabIndex
end tell
repeat with i in tabID
try
set tabID to item 1 of i
exit repeat
end try
end repeat
try
tabID as number
on error eStr
set AppleScript's text item delimiters to " of "
repeat with i in (text items of eStr)
if i contains "window id" then
set winOfTabID to run script ((contents of i) & " of application \"Safari\"")
exit repeat
end if
end repeat
end try
set winOfTabIdDoc to winOfTabID's document
if current tab of winOfTabID ≠ tabID then set current tab of winOfTabID to tabID
if winOfTabIdDoc ≠ frontWindoc then
set newDoc to make new document
set index of winOfTabID to 1
close newDoc
end if
end tell
on error e number n
set e to e & return & return & "Num: " & n
tell me to set dDlg to display dialog e with title "ERROR!" buttons {"Cancel", "Copy", "OK"} default button "OK"
if button returned of dDlg = "Copy" then set the clipboard to e
end try
-------------------------------------------------------------------------------------------