• 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: Procedure Problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Procedure Problem


  • Subject: Re: Procedure Problem
  • From: has <email@hidden>
  • Date: Tue, 11 Mar 2003 17:00:58 +0000

Darwin Zins wrote:

Can anyone tell me why I can't do this:

tell application "Address Book"
repeat with aPerson in every person
my set_a_vars(aPerson)
end repeat
end tell

on set_a_vars(aCard)
repeat with aPhone in (every phone of aCard)
tell aPhone
[...]
end tell
end repeat
end set_a_vars

This is a compiler issue; a side-effect of the very clever but slightly kludgy trick the AS compiler uses to recognise application-specific keywords. In short, when it encounters a 'tell application "AppName"' block it includes terms from that app's dictionary in its list of known keywords while parsing code within that block. The rest of the time, the only keywords it recognises are those from osaxen and the AppleScript language itself.

So while your code's design is perfectly logical and would function fine in its compiled form, the compiler doesn't know how to compile it correctly because it lacks the terminology to do so. As a result, it either compiles your source wrongly or barfs completely complaining of an unrecognised term.

The simplest solution is just to add a 'tell application "AppName"' block, for the compiler's benefit if nothing else:

on set_a_vars(aCard)
tell application "Address Book"
repeat with aPhone in (every phone of aCard)
tell aPhone
[...]
end tell
end repeat
end tell
end set_a_vars


It's a bit redundant as you're not sending any commands to the application object itself, but it's standard practice and something every scripter understands. If you really wanted to show off, I guess you could use a 'using terms from' block instead. But I don't see much point (and, as this example shows, too much cleverness doesn't always go down too well in any case:).

has
--
http://www.barple.pwp.blueyonder.co.uk -- The Little Page of AppleScripts
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: System Events problem
  • Next by Date: Re: Big numbers (again) and complex routine
  • Previous by thread: Re: Procedure Problem
  • Next by thread: QXP5 and Layers
  • Index(es):
    • Date
    • Thread