Le 18 juil. 2016 à 01:31, Mitchell L Model <
email@hidden> a écrit :
I guess I was wrong that making Safari the parent of the Script object means that all of its handlers know Safari's vocabulary. I have only recently started to use Script objects, because for the kind of scripts I write I have never seen the point of using them. I thought one use was precisely to establish this kind of vocabulary context. It gets tedious putting a "tell application" in each of many handlers. Does "using vocabulary" help for that purpose? Where would I put it to wrap a bunch of handlers?
On Jul 17, 2016, at 4:56 AM, Yvan KOENIG <
email@hidden> wrote:
Clearly, when you enter the handler, the code doesn't know that it's a Safari one.
In my message I gave a script showing how to use "using terms from".
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
As the on run handler correctly treated the window property we may think that it correctly understand that its code speaks to Safari.
So, this alternate scheme seems correct too.
script logWindows
property parent : application "Safari"
on run
activate
repeat with theWindow in the windows
my logWindow(theWindow)
end repeat
end run
using terms from application "Safari" # ADDED
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
In fact I ran it with no problem.
Yvan KOENIG running El Capitan 10.11.5 in French (VALLAURIS, France) lundi 18 juillet 2016 11:11:06