Le 17 juil. 2016 à 04:04, Mitchell L Model < email@hidden> a écrit :
…
This is as close as I have come. There is still an error in logWindow.
script logWindows property parent : application "Safari"
on run activate repeat with theWindow in the windows my logWindow(theWindow) end repeat end run
on logWindow(theWindow) log the name of theWindow as item
-- Safari got an error: Can’t make |tabs| of item 1 of every window into type reference. set allTabs to the tabs of theWindow
repeat with theTab in allTabs my logTab(theTab) end repeat end logWindow
on logTab(theTab) log " " & the name of theTab as item end logTab
end script
run logWindows
_
I just opened my eyes and saw what is wrong. Look at the instruction: set allTabs to the tabs of theWindow It's exactly the way it appears in the editor. As you may see, tabs appears as a variable name, not as a class of object which would appear as : set allTabs to the tabs of theWindow
Clearly, when you enter the handler, the code doesn't know that it's a Safari one.
Edit it as :
script logWindows property parent : application "Safari"
on run activate repeat with theWindow in the windows my logWindow(theWindow) end repeat end run
on logWindow(theWindow) tell application "Safari" # ADDED log the name of theWindow as item
-- Safari got an error: Can’t make |tabs| of item 1 of every window into type reference. set allTabs to the tabs of theWindow
repeat with theTab in allTabs my logTab(theTab) end repeat end tell # ADDED end logWindow
on logTab(theTab) log " " & the name of theTab as item end logTab
end script
run logWindows
and it will work because now the code knows that it is a Safari one.
I guess that your problems are due to the use of : property parent : application "Safari" which let you thing - wrongly - that every piece of code in the script will know that it's a Safari one.
It's why I never use this syntax.
I always code this way :
script logWindows -- property parent : application "Safari" # DISABLED
on run tell application "Safari" # ADDED activate repeat with theWindow in the windows my logWindow(theWindow) end repeat end tell # ADDED end run
on logWindow(theWindow) tell application "Safari" # ADDED log the name of theWindow as item
-- Safari got an error: Can’t make |tabs| of item 1 of every window into type reference. set allTabs to the tabs of theWindow
repeat with theTab in allTabs my logTab(theTab) end repeat end tell # ADDED end logWindow
on logTab(theTab) log " " & the name of theTab as item end logTab
end script
run logWindows
With this structure I don't have to guess which is the application I am speaking to, I know exactly what I am doing.
If you really want to use the original syntax, play safety as I do below and it will work.
script logWindows property parent : application "Safari" using terms from application "Safari" # ADDED on run activate repeat with theWindow in the windows my logWindow(theWindow) end repeat end run
on logWindow(theWindow) log the name of theWindow as item
-- Safari got an error: Can’t make |tabs| of item 1 of every window into type reference. set allTabs to the tabs of theWindow
repeat with theTab in allTabs my logTab(theTab) end repeat end logWindow
on logTab(theTab) log " " & the name of theTab as item end logTab end using terms from end script
run logWindows
To be completely honest, I will not be comfortable with this late structure because - I don't know why and never took care of that before- the instruction end using terms from refuse to compile if I try to add a comment at its end.
Yvan KOENIG running El Capitan 10.11.5 in French (VALLAURIS, France) dimanche 17 juillet 2016 10:55:34
|