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

Fwd: need explanation for trivial Safari script behavior


  • Subject: Fwd: need explanation for trivial Safari script behavior
  • From: Yvan KOENIG <email@hidden>
  • Date: Mon, 18 Jul 2016 12:23:05 +0200

Oops.
One more time I sent my message to the asker, not to the list !


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






 _______________________________________________
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: [ANN] Script Debugger 6 ASObjC Resources
  • Next by Date: Re: need explanation for trivial Safari script behavior
  • Previous by thread: Re: need explanation for trivial Safari script behavior
  • Next by thread: [ANN] Script Debugger 6 ASObjC Resources
  • Index(es):
    • Date
    • Thread