• 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
Re: need explanation for trivial Safari script behavior
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: need explanation for trivial Safari script behavior


  • Subject: Re: need explanation for trivial Safari script behavior
  • From: Christopher Stone <email@hidden>
  • Date: Mon, 18 Jul 2016 07:02:14 -0500

On Jul 17, 2016, at 05:17, Axel Luttgens <email@hidden> wrote:
By running this one

tell application "Safari"
   repeat with theWindow in windows
      name of theWindow
   end repeat
end tell

it appears everything behaves as expected: upon each iteration, the name of the corresponding window is returned.


The trouble with this is that not all windows are documents.

To get only document windows we need a filter:

set winList to windows where its document is not missing value

When I'm writing and debugging something like that I never depend upon the log, and I'll write it something like this.

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

set windowNameList to {}

tell application "Safari"

   

   set winList to windows where its document is not missing value

   

   repeat with theWindow in winList
      set end of windowNameList to name of theWindow
      "" --<-- BREAKPOINT
   end repeat

   

end tell

windowNameList

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

That way the value of winList is NOT hidden from me.

Of course since I write all my code in Script Debugger I can set breakpoints and inspect variable values live in the variable inspector panel.

Something like this while more terse than the above is not conducive to good debugging.

--------------------------------------------------------------------------------
set windowNameList to {}
tell application "Safari"
repeat with theWindow in (windows where its document is not missing value)
set end of windowNameList to name of theWindow
end repeat
end tell
windowNameList
--------------------------------------------------------------------------------

There will always be some instance where you need to inspect what's in the list you're iterating through.

When extracting data from Safari it is often more efficient to get the data and then processes it as needed.

--------------------------------------------------------------------------------
tell application "Safari"
tell (windows where its document is not missing value)
set winNameList to name
set winUrlList to URL of its document
set tabNameList to name of tabs
set tabUrlList to URL of tabs
end tell
end tell
--------------------------------------------------------------------------------

Axel makes a great point about how logging works.

It has bitten me too many times, so I only use it when it is of real value to me.

--
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

  • Follow-Ups:
    • Re: need explanation for trivial Safari script behavior
      • From: Mitchell L Model <email@hidden>
References: 
 >need explanation for trivial Safari script behavior (From: Mitchell L Model <email@hidden>)
 >Re: need explanation for trivial Safari script behavior (From: Axel Luttgens <email@hidden>)

  • Prev by Date: Fwd: need explanation for trivial Safari script behavior
  • Next by Date: How to create a document?
  • Previous by thread: Re: need explanation for trivial Safari script behavior
  • Next by thread: Re: need explanation for trivial Safari script behavior
  • Index(es):
    • Date
    • Thread