• 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: Yvan KOENIG <email@hidden>
  • Date: Sun, 17 Jul 2016 10:56:38 +0200


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




 _______________________________________________
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>
    • 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: "Stockly, Ed" <email@hidden>)
 >RE: need explanation for trivial Safari script behavior (From: "Stockly, Ed" <email@hidden>)
 >Re: need explanation for trivial Safari script behavior (From: Mitchell L Model <email@hidden>)

  • Prev by Date: Re: need explanation for trivial Safari script behavior
  • 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: Re: need explanation for trivial Safari script behavior
  • Index(es):
    • Date
    • Thread