------------------------------------------------------------------------------------------------
# Author: Christopher Stone
# Created: 2010-10-16 : 00:42
# Modified: 2012-04-25 : 02:06
# Application: Safari
# Purpose: Display a list of tab names and also a count of both documents & tabs.
# Select a tab name to bring it to the front.
# Dependencies: none
------------------------------------------------------------------------------------------------
try
set sep to "----------------------------------------------------------------------------------------------------"
tell application "Safari"
tell (every window where its document is not missing value)
set curntTabIdx to index of current tab
set tabCount to count of tabs
set tabNames to name of tabs
end tell
set currentTabName to (name of current tab of front window) & " [✓]"
set frontWindoc to front window's document
set docCount to count of documents
if docCount < 10 then set docCount to "0" & docCount
set hdrText to "Window Count: " & docCount & return & " Tab Count: " & tabCount
set ndx to 0
repeat with i in tabNames
set ndx to ndx + 1
tell (a reference to i's item (item ndx of curntTabIdx))
set its contents to (its contents) & " [✓]"
end tell
set end of i to sep
end repeat
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)
set tabName to choose from list tabNames with title "•• Safari Tab Names ••" with prompt hdrText ¬
default items {currentTabName} with empty selection allowed
if tabName = false then return
set tabName to item 1 of tabName
if tabName ends with " [✓]" then
set AppleScript's text item delimiters to " [✓]"
set tabName to text item 1 of tabName
end if
set tabID to tabs of windows whose name contains tabName
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 eMsg number eNum
set {c, s} to {return, "------------------------------------------"}
set e to s & c & "Error: " & eMsg & c & s & c & "Error Number: " & eNum & c & s
beep
display dialog e
end try
------------------------------------------------------------------------------------------------
# Not presently used in the script.
on DUPE_TAB_NAME_CHECK()
tell application "Safari" to set tabNames to name of tabs of (every window where its document is not missing value)
set {oldTIDS, AppleScript's text item delimiters} to {AppleScript's text item delimiters, linefeed}
set tabNames to tabNames as text
set AppleScript's text item delimiters to oldTIDS
if (do shell script "echo " & quoted form of tabNames & " | sort -n | uniq -d") = "" then
set duplicateTabFlag to false
else
set duplicateTabFlag to true
end if
end DUPE_TAB_NAME_CHECK
------------------------------------------------------------------------------------------------
on DUPE_TAB_NAME_URL_CHECK()
tell application "Safari" to set {tabNames, urlList} to {name, URL} of tabs of (every window where its document is not missing value)
set {oldTIDS, AppleScript's text item delimiters} to {AppleScript's text item delimiters, linefeed}
set tabInfo to {tabNames, urlList} as text
set AppleScript's text item delimiters to oldTIDS
if (do shell script "echo " & quoted form of tabInfo & " | sort -n | uniq -d") = "" then
return false
else
return true
end if
end DUPE_TAB_NAME_URL_CHECK
------------------------------------------------------------------------------------------------