• 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 10.1 on macOS 10.12.4 – Getting Valid Document Windows
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Safari 10.1 on macOS 10.12.4 – Getting Valid Document Windows


  • Subject: Safari 10.1 on macOS 10.12.4 – Getting Valid Document Windows
  • From: Christopher Stone <email@hidden>
  • Date: Sun, 30 Apr 2017 23:39:58 -0500

Hey Folks,

Safari 10.1 (12603.1.30.0.34) on macOS 10.12.4 has broken several things I know of.

My 12 year old method of reliably getting document windows:

------------------------------------------------------------------------------
tell application "Safari"
    set winList to windows where its document is not missing value
end tell
------------------------------------------------------------------------------

Safari's ability to see its own Preferences Window.

Output of a one-dimensional array from a do _javascript_ statement to an AppleScript list.  (You now have to flatten the list in your _javascript_ – output as text – and convert back to a list.)

And there may be more we haven't found yet.

I was briefly excited by the fact that this:

------------------------------------------------------------------------------
tell application "Safari"
    set winList to windows
end tell
------------------------------------------------------------------------------

Produced a clean list of document windows on my system.  BUT – unfortunately several reports have come in from users who still have errant invisible non-document windows in the list.

So – for the time being I judge that code unreliable.

Personally I don't understand why we don't have subclasses for windows like document window, preferences window, etc.  Eudora had such goodies 20 years ago...

In any case – the problem is to find a bombproof method to get only valid document windows.

This is ugly but is quite fast and seems to fill the requirement.

------------------------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2017/04/30 23:01
# dMod: 2017/04/30 23:17
# Appl: Safari
# Task: List all valid document windows.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Safari, @List, @Valid, @Document, @Windows
# Note: Due to problems in Safari 10.1 on macOS 10.12.4.
------------------------------------------------------------------------------

tell application "Safari"
    set winList to current tab of windows
    try
        winList / 0
    on error e
        set AppleScript's text item delimiters to {"window id ", " of "}
        set winList to text items of e
    end try
    repeat with i in winList
        try
            if (contents of i) ≠ "" then
                set (contents of i) to (contents of i) as integer
            end if
        end try
    end repeat
    set winList to integers of winList
    repeat with i in winList
        set contents of i to window id (contents of i)
    end repeat

    

    winList

    

end tell

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

--
Best Regards,
Chris

 _______________________________________________
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

  • Prev by Date: Re: Browser tab
  • Previous by thread: Re: Browser tab
  • Index(es):
    • Date
    • Thread