• 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
Getting Tab Index and Window ID in Safari
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Getting Tab Index and Window ID in Safari


  • Subject: Getting Tab Index and Window ID in Safari
  • From: Christopher Stone <email@hidden>
  • Date: Sat, 20 May 2017 18:15:07 -0500

Hey Folks,

Some clever code posted by someone recently inspired me to take a slightly different tack at getting Safari's Tab-Indexes and Window-IDs.

The vanilla version is very fast.  The Satimage.osax version is faster still.

Output is a list of integers for the vanilla version:

--> {1, 598, 1, 621, 1, 606, 2, 606}

Output for the Satimage.osax version is a list of digit strings:

--> {"1", "598", "1", "621", "1", "606", "2", "606"}

Each pair represents a Tab-Index/Window-ID.

I'll post a script in a minute that makes use of this technique.

--
Best Regards,
Chris

------------------------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2017/05/20 17:30
# dMod: 2017/05/20 17:42
# Appl: Safari
# Task: Get Tab Index and Window ID of every window as a list
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Safari, @Tab_Index, @Window_ID
------------------------------------------------------------------------------

tell application "Safari" to set tabWinList to tabs of windows

try
    tabWinList / 0
on error eMsg
    set AppleScript's text item delimiters to {"Can’t make ", " into type real.", "of application \"Safari\"", " of window id", "«class bTab»"}
    set tabWinList to text items of eMsg
    set AppleScript's text item delimiters to linefeed
    set tabWinList to tabWinList as text
    set tabWinList to words of tabWinList
    repeat with theWord in tabWinList
        try
            set contents of theWord to theWord as integer
        on error
            set contents of theWord to "null"
        end try
    end repeat
end try

set tabWinList to integers of tabWinList

------------------------------------------------------------------------------


------------------------------------------------------------------------------
# Satimage.osax Version
------------------------------------------------------------------------------

tell application "Safari" to set tabWinList to tabs of windows

try
    tabWinList / 0
on error eMsg
    set tabWinList to fnd("\\d+", eMsg, true, true) of me
end try

------------------------------------------------------------------------------
--» HANDLERS
------------------------------------------------------------------------------
on fnd(_find, _data, _all, strRslt)
    try
        find text _find in _data all occurrences _all string result strRslt with regexp without case sensitive
    on error
        return false
    end try
end fnd
------------------------------------------------------------------------------

 _______________________________________________
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: Getting Tab Index and Window ID in Safari
      • From: Yvan KOENIG <email@hidden>
  • Prev by Date: Re: Two Windows in the Calendar app?
  • Next by Date: Safari - Bring a tab containing a given URL to the front
  • Previous by thread: Re: Comma delimited paragraph
  • Next by thread: Re: Getting Tab Index and Window ID in Safari
  • Index(es):
    • Date
    • Thread