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