• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Safari Tab Pick-List
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Safari Tab Pick-List


  • Subject: Safari Tab Pick-List
  • From: Christopher Stone <email@hidden>
  • Date: Wed, 25 Apr 2012 03:06:03 -0500

Hey Folks,

I've had a variant of this script for years, but I've just used it for information - to see how many tabs and windows were open.  I've been meaning to make it switch to the tab selected in the choose-from list but have never gotten 'round to it.

Today I got ticked-off and wrote a new one, because I had a huge number of windows/tabs open in Safari and couldn't get where I wanted to go easily enough.

It presents a choose-from-dialog with the available tabs and windows along with a count of all documents and tabs.

Current tabs in each window have '[✓]' as their suffix.

Picking a tab will bring its window to the foreground and switch to the tab if necessary.

The script is strictly vanilla.

I run mine with a keyboard shortcut from FastScripts, but any Applescript-runner should do.

I was going to incorporate a check for duplicate tab names and urls, but I haven't decided how I want to handle them.  There's a couple of preliminary dupe-check handler appended (not incorporated into the script yet).

Enjoy.

--
Best Regards,
Chris


------------------------------------------------------------------------------------------------
#       Author: Christopher Stone
#      Contact: email@hidden>
#      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
------------------------------------------------------------------------------------------------
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: Safari Tab Pick-List
      • From: Alex Zavatone <email@hidden>
  • Prev by Date: Re: [ASOC] 'store script' still broken?
  • Next by Date: Re: Safari Tab Pick-List
  • Previous by thread: Re: property
  • Next by thread: Re: Safari Tab Pick-List
  • Index(es):
    • Date
    • Thread